import java.awt.Image;
import java.io.IOException;

import javax.imageio.ImageIO;

import java.util.Random;

public class GarbageChute extends Platform implements java.io.Serializable {
	static final long serialVersionUID = 1L;

	public static final int type = 0;
	public static final int size = 128;
	private static final int images_num = 1; //このクラスの総使用画像数
	private static final int anime_pattern = 1; //このクラスのアニメーション数
	private static int AnimeImagesNum[] = {1};//アニメごとに何枚使うか
	private static Image[] images = new Image[images_num];
	protected Random rnd = new Random();
	
	public static void loadImages (ClassLoader loader) throws IOException {
		final String path = "images/";
		images[0] = ImageIO.read(loader.getResourceAsStream(path+"garbagechute.png"));		
		images[0] = images[0].getScaledInstance(size*9/8, size*3/4, Image.SCALE_AREA_AVERAGING);
	}

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

	public int getSize() {
		return size;
	}

	public int checkOnObj( 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軸比較
						run( o );
						return 1;
					}
				}
			}
		return 0;
	}
	
	public int run( Obj o ) {
		o.remove();
		return 0;
	}

	public GarbageChute(int initX, int initY, Direction initDir) {
		super(initX, initY, Platform.Direction.BACK);
	}
}