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

public class TDProjectile {
	int dir, projX, projY;
	TDLevel l;
	boolean hit = false;
	public TDProjectile(TDLevel lev, int direction, int x, int y) {
		l = lev;
		dir = direction;
		projX = x;
		projY = y;
	}
	public void draw(Graphics2D g) {
		if(dir == 0) {
			g.drawLine(projX, projY, projX-7, projY);
			projX -= 2;
		} else if(dir == 1) {
			g.drawLine(projX, projY, projX+7, projY);
			projX += 2;
		} else if(dir == 2) {
			g.drawLine(projX, projY, projX, projY-7);
			projY -= 2;
		} else if(dir == 3) {
			g.drawLine(projX, projY, projX, projY+7);
			projY += 2;
		}
	}
	public void hitDetect() {
		Iterator<TDEnemy> it = l.enemies.iterator();
		while(it.hasNext()) {
			TDEnemy e = it.next();
			if(e.getX()+8 <= projX+8 && e.getX()+8 >= projX-8 && 
			   e.getY()+8 <= projY+8 && e.getY()+8 >= projY-8) {
			   		hit = true;
			   		it.remove();
			}
		}
	}
	public boolean isOffScreen() {
		return (projX<0 || projX>256 || projY<0 || projY>256);
	}
	public boolean hitTarget() {
		return hit;
	}
}