public class TDPlayer extends Sprite{
	private static final int[] animLengths = {4,4};
	float dx,dy;
	byte keyMoveState, keyFireState;
	TDLevel l;
	int dir = 4;
	public TDPlayer(TDLevel l, String imgPath) {
		super(l.spriteCache, imgPath+"hobotd/hobo", animLengths);
		this.l=l;
		dx=dy=2;
	}
	public TDPlayer(TDLevel l, float x, float y, String imgPath) {
		this(l, imgPath);
		setLoc(x,y);
	}
	public void setMoveKeys(byte keyMoveState) {
		this.keyMoveState = keyMoveState;
	}
	public void setFireKeys(byte keyFireState) {
		this.keyFireState = keyFireState;
	}
	public void die() {
		l.gamestate.addLives(-1);
		l.gamestate.addPoints(-2);
		x = spawnPoint();
		y = spawnPoint();
	}
	public int spawnPoint() {
		double round = 2+Math.random()*13;
		int spawn = (int)round;
		int point = spawn*16;
		return point;
	}
	public void act(){
		dir = 4;
		if((KEY_DOWN & keyMoveState) != 0) {
			y+=dy;
			setSpriteMode(1);
		}
		if((KEY_UP & keyMoveState) != 0) {
			y-=dy;
			setSpriteMode(0);
		}
		if((KEY_LEFT & keyMoveState) != 0) {
			x-=dx;
		}
		if((KEY_RIGHT & keyMoveState) != 0) {
			x+=dx;
		}
		if((KEY_PRJ_LEFT & keyFireState) != 0) {
			dir = 0;
		}
		else if((KEY_PRJ_RIGHT & keyFireState) != 0) {
			dir = 1;
		}
		else if((KEY_PRJ_UP & keyFireState) != 0) {
			dir = 2;
		}
		else if((KEY_PRJ_DOWN & keyFireState) != 0) {
			dir = 3;
		}
		if((x+12) == 256) {
			x-=dx;
		}
		if(x == 0) {
			x+=dx;
		}
		if((y+14) == 256) {
			y-=dy;
		}
		if(y == 0) {
			y+=dy;
		}
	}
}
