
public class TDEnemy extends Sprite {
	private static final int[] animLengths = {4,4,4,4};
	public TDLevel l;
	TDPlayer p;
	float dx, dy;
	float speed;
	int count;
	public TDEnemy(TDLevel l, String imgPath) {
		super(l.spriteCache, imgPath+"hooverbot/hbot", animLengths);
		this.l = l;
		p = l.player;
		x = spawnPoint()*16;
		y = spawnPoint()*16;
		speed=.5f+(l.gamestate.getKills()-l.initKills)*0.02f;
		dx=dy=0;
		count = 0;
	}
	public TDEnemy(TDLevel l, float x, float y, String imgPath) {
		this(l, imgPath);
		setLoc(x,y);
	}
	public int spawnPoint() {
		int spawn = (int)(2+Math.random()*13);
		int point = spawn*16;
		while (p.x+8 >= point-16 && p.x+8 <= point+16 &&
					p.y+8 >= point-16 && p.y+8 <= point+16) {
			spawn = (int)(2+Math.random()*13);
			point = spawn*16;
		}
		return spawn;
	}
	public void act() {
		count++;
		if(Math.abs(x-p.getX()) <= 8 && Math.abs(y-p.getY()) <= 8)
			p.die();
		if((x+6) >= 242) {
			dx = -1 * speed;
			dy = 0;
		}
		if(x <= 6) {
			dx = speed;
			dy = 0;
		}
		if((y+6) >= 242) {
			dy = -1 * speed;
			dx = 0;
		}
		if(y <= 6) {
			dy = speed;
			dx = 0;
		}
		if (count%32 == 0 || (dx==0 && dy==0)) {
			if (Math.abs(x - p.x) > Math.abs(y - p.y)) {
				if (Math.signum(x - p.x) < 0)
					setSpriteMode(1);
				else
					setSpriteMode(3);
				dx = speed * Math.signum(p.x - x);
				dy = 0;
			} else {
				if (Math.signum(y - p.y) < 0)
					setSpriteMode(2);
				else
					setSpriteMode(0);
				dy = speed * Math.signum(p.y - y);
				dx = 0;
			}
		}
		x+=dx;
		y+=dy;
	}
}