import java.awt.event.*;
import java.awt.*;
import java.awt.image.*;
public class HWPlatformer extends HWMainDisplay {
	private static final long serialVersionUID = 3;
	Level lev;
	
	public HWPlatformer(HWDisplay frame, int levelNum, LevelDec levelInfo) {
		super(frame);
		lev = new Level(frame, levelNum, levelInfo);
		ked = new KeyEventDispatcher() {
			byte keyState = 0;
			public boolean dispatchKeyEvent(KeyEvent e) {
				if (e.getID()==KeyEvent.KEY_PRESSED) {
					if (e.getKeyCode() == KeyEvent.VK_LEFT) {
						keyState |= Sprite.KEY_LEFT;
					} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
						keyState |= Sprite.KEY_RIGHT;
					} else if (e.getKeyCode() == KeyEvent.VK_UP) {
						keyState |= Sprite.KEY_JUMP;
					} else if (e.getKeyCode() == KeyEvent.VK_T) {
						keyState |= Sprite.KEY_RUN;
					} else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
						keyState |= Sprite.KEY_FIRE;
					}
				} else if (e.getID()==KeyEvent.KEY_RELEASED) {
					if (e.getKeyCode() == KeyEvent.VK_LEFT) {
						keyState &= ~Sprite.KEY_LEFT;
					} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
						keyState &= ~Sprite.KEY_RIGHT;
					} else if (e.getKeyCode() == KeyEvent.VK_UP) {
						keyState &= ~Sprite.KEY_JUMP;
					} else if (e.getKeyCode() == KeyEvent.VK_T) {
						keyState &= ~Sprite.KEY_RUN;
					} else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
						keyState &= ~Sprite.KEY_FIRE;
					}
				}
				lev.player.setKeys(keyState);
				return false;
			}
		};
		
	}
	
	protected int getImgSize() {
		return 256;
	}
	
	public void update(BufferedImage img) {
		lev.update(img);
		if (frame.gamestate.getLives() < 0) {
			frame.menu.gameOver();
			frame.changeTo(frame.menu);
		}
	}
	protected void paintComponent(Graphics g) {
		g.drawImage(screen, 0, 0, 512, 512, 0, 0, 256, 256, null);
	}
}

