import java.awt.Image;
import java.util.*;

public class ObjEX extends Obj implements java.io.Serializable {
	static final long serialVersionUID = 1L;
	public int type;

	protected Image[] images;

	public static List<ObjEX> objEXList = new ArrayList<ObjEX>();
	
	public static final int YUKKURI = 1;
	public static final int SHIT	= 2;
	public static final int FOOD	= 4;
	public static final int TOILET	= 8;
	public static final int TOY		= 16;
	public static final int	PLATFORM= 32;
	public static final int	FIX_OBJECT= 64;
	public static final int hitCheckObjType 		= 0;

	public static enum Direction {BACK, THISSIDE, RIGHT, LEFT};
	public static final int PLATFORM_BACK = 0;
	public static final int PLATFORM_THISSIDE = 1;
	public static final int PLATFORM_RIGHT = 2;
	public static final int PLATFORM_LEFT = 3;
	protected Direction direction;
	protected static int size;

	public Image getImage(){
		return images[0];
	}

	@Override
	public int getSize() {
		return size;
	}

	public static int getSizeS() {
		return size;
	}

	public Direction getDirection() {
		return direction;
	}

	public int getHitCheckObjType() {
		return hitCheckObjType;
	}

	public int checkHitObj( Obj o ) {
		int objX = o.getX();
		int objY = o.getY();
		int objZ = o.getZ();
		int platformSize = getSize()/2;
		int platformX = getX();
		int platformY = getY();
		int platformZ = getZ();
		int offsetX = (Body.MAXSIZE - getSize())*7/32-28;
		int offsetY = (Body.MAXSIZE - getSize())*6/16-40;
		if ( objZ == 0 ){	//空中の物は移動させない
			if ((platformX + offsetX)<=(objX) && (objX)<=(platformX + offsetX + platformSize)){	//X軸比較
				if ((platformY + offsetY)<=(objY) && (objY)<=(platformY + offsetY + platformSize)){	//Y軸比較
					objHitProcess( o );
					return 1;
				}
			}
		}
		return 0;
	}

	public int objHitProcess( Obj o ) {
		return 0;
	}
	
	public void upDate() {
	}

	public void buyObj() {
		Cash.addCash(-getValue());
	}

	@Override
	public Event clockTick()
	{
		age += TICK;
		if (removed) {
			removeListData();
			return Event.REMOVED;
		}
		if (!grabbed) {
			if (vx != 0) {
				x += vx;
				if (x < 0) {
					x = 0;
					vx *= -1;
				}
				else if (x > Terrarium.MAX_X) {
					x = Terrarium.MAX_X;
					vx *= -1;
				}
				else if (Terrarium.onBarrier(x, y, Body.MAXSIZE/4)) {
					x -= vx;
					vx = 0;
				}
			}
			if (vy != 0) {
				y += vy;
				if (y < 0) {
					y = 0;
					vy *= -1;
				}
				else if (y > Terrarium.MAX_Y) {
					y = Terrarium.MAX_Y;
					vy *= -1;
				}
				else if (Terrarium.onBarrier(x, y, Body.MAXSIZE/4)) {
					y -= vy;
					vy = 0;
				}
			}
			if (z != 0 || vz != 0) {
				vz += 1;
				z -= vz;
				if (z <= 0 || objType == Type.PLATFORM ) {
					z = 0;
					vx = 0;
					vy = 0;
					vz = 0;
				}
			}
		}
		upDate();
		return Event.DONOTHING;
	}
	
	public void removeListData(){
		objEXList.remove(this);
	}

	public ObjEX(int initX, int initY, Direction initDir) {
		objType = Type.PLATFORM;
		//objEXList.add(this);
		x = initX;
		y = initY;
		z = 0;
		direction = initDir;
		//Cash.addCash(-getValue());
	}
}