import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
public class HWTopDown extends HWMainDisplay {
	private static final long serialVersionUID = 5;
	TDLevel lev;
	
	 
	public HWTopDown(HWDisplay frame, int levelNum, LevelDec levelInfo) {
		super(frame);
		lev = new TDLevel(frame, frame.gamestate, levelNum, levelInfo.imgPath, levelInfo.levelmap);
		this.setPreferredSize(new Dimension(lev.winX,lev.winY));
		ked = new KeyEventDispatcher() {
			byte keyFireState = 0;
			byte keyMoveState = 0;
			public boolean dispatchKeyEvent(KeyEvent e) {
				if (e.getID()==KeyEvent.KEY_PRESSED) {
					if (e.getKeyCode() == KeyEvent.VK_A) {
						keyFireState |= Sprite.KEY_PRJ_LEFT;
					} else if (e.getKeyCode() == KeyEvent.VK_D) {
						keyFireState |= Sprite.KEY_PRJ_RIGHT;
					} else if (e.getKeyCode() == KeyEvent.VK_W) {
						keyFireState |= Sprite.KEY_PRJ_UP;
					} else if (e.getKeyCode() == KeyEvent.VK_S) {
						keyFireState |= Sprite.KEY_PRJ_DOWN;
					} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
						keyMoveState |= Sprite.KEY_LEFT;
					} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
						keyMoveState |= Sprite.KEY_RIGHT;
					} else if (e.getKeyCode() == KeyEvent.VK_UP) {
						keyMoveState |= Sprite.KEY_UP;
					} else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
						keyMoveState |= Sprite.KEY_DOWN;
					}
				} else if (e.getID()==KeyEvent.KEY_RELEASED) {
					if (e.getKeyCode() == KeyEvent.VK_A) {
						keyFireState &= ~Sprite.KEY_PRJ_LEFT;
					} else if (e.getKeyCode() == KeyEvent.VK_D) {
						keyFireState &= ~Sprite.KEY_PRJ_RIGHT;
					} else if (e.getKeyCode() == KeyEvent.VK_W) {
						keyFireState &= ~Sprite.KEY_PRJ_UP;
					} else if (e.getKeyCode() == KeyEvent.VK_S) {
						keyFireState &= ~Sprite.KEY_PRJ_DOWN;
					} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
						keyMoveState &= ~Sprite.KEY_LEFT;
					} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
						keyMoveState &= ~Sprite.KEY_RIGHT;
					} else if (e.getKeyCode() == KeyEvent.VK_UP) {
						keyMoveState &= ~Sprite.KEY_UP;
					} else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
						keyMoveState &= ~Sprite.KEY_DOWN;
					}
				}
				lev.player.setMoveKeys(keyMoveState);
				lev.player.setFireKeys(keyFireState);
				return false;
			}
		};
	}
	protected int getImgSize() {
		return 256;
	}
	protected void update(BufferedImage img) {
		lev.update(img);
		if (frame.gamestate.getLives() < 0) {
			frame.menu.gameOver();
			frame.changeTo(frame.menu);
		}
	}
}
