import java.awt.Graphics2D;


public class Projectile extends Sprite {
	private static final int[] animLengths = {1};
	private Level l;
	private float vx;

	public Projectile(Level l, float x, float y, float vx) {
		super(l.spriteCache, "img/items/projectile", animLengths);
		this.l=l;
		this.vx = vx;
		setLoc(x,y);
		setVX(vx);
	}
	public void setVX(float vx) {
		this.vx = vx;
	}
	public void draw(Graphics2D g, int x, int y) {
		super.draw(g, x+8, y+8);
	}
	
	public boolean hitSprite(Sprite spr) {
		return (spr.getX()+spr.getW()*32>x+8 && x+24>spr.getX() &&
				spr.getY()+spr.getH()*32>y+8 && y+24>spr.getY());
	}
	
	public void act() {
		x+=vx;
		for (Enemy e : l.enemies) {
			if (hitSprite(e) && e.isMoving()) {
				e.die();
				setToDestroy(true);
			}
		}
		if (l.hitDetect((int)x+8, (int)y+8, 16, 16, vx, 0) != 0)
			setToDestroy(true);
		if (!l.onScreen(this))
			setToDestroy(true);
		
	}

}
