package hypernova.pilots;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import org.apache.log4j.Logger;

import hypernova.Universe;
import hypernova.Ship;

public class KeyboardPilot extends Pilot implements KeyListener {
    private static Logger log = Logger.getLogger("KeyboardPilot");
    private static KeyboardPilot INSTANCE = new KeyboardPilot();

    private KeyboardPilot() {
        super(null);
    }

    public static KeyboardPilot get() {
	return INSTANCE;
    }

    @Override
    public void keyPressed(KeyEvent e) {
        log.trace("keyPressed() " + e);
	Ship ship = getShip();
	if(ship == null) {
	    log.trace("no ship");
	    return;
	}

        switch (e.getKeyCode()) {
        case KeyEvent.VK_LEFT:
            ship.turnLeft(true);
            break;
        case KeyEvent.VK_RIGHT:
            ship.turnRight(true);
            break;
        case KeyEvent.VK_UP:
            ship.setEngines(1.0);
            break;
        case KeyEvent.VK_DOWN:
            ship.setEngines(-1.0);
            break;
        case KeyEvent.VK_SPACE:
            ship.setFire(0, true);
            break;
        default:
            log.trace("Unkown key " + e.getKeyCode());
        }
    }

    @Override
    public void keyReleased(KeyEvent e) {
        log.trace("keyReleased() " + e);
	Ship ship = getShip();
	if(ship == null) {
	    log.trace("no ship");
	    return;
	}

        switch (e.getKeyCode()) {
        case KeyEvent.VK_LEFT:
            ship.turnLeft(false);
            break;
        case KeyEvent.VK_RIGHT:
            ship.turnRight(false);
            break;
        case KeyEvent.VK_UP:
            ship.setEngines(false);
            break;
        case KeyEvent.VK_DOWN:
            ship.setEngines(false);
            break;
        case KeyEvent.VK_SPACE:
            ship.setFire(0, false);
            break;
        }
    }

    @Override
    public void keyTyped(KeyEvent e) {}

    @Override
    public void drive(double dt) {
        /* Driving is handled entirely by keyboard events. */
    }
}

@@ -734,32 +734,60 @@
 yEvent.VK_LEFT:%0A
+        case KeyEvent.VK_A:%0A
             ship
@@ -795,32 +795,32 @@
 turnLeft(true);%0A
-
             brea
@@ -846,32 +846,60 @@
 Event.VK_RIGHT:%0A
+        case KeyEvent.VK_D:%0A
             ship
@@ -956,32 +956,60 @@
 KeyEvent.VK_UP:%0A
+        case KeyEvent.VK_W:%0A
             ship
@@ -1068,32 +1068,60 @@
 yEvent.VK_DOWN:%0A
+        case KeyEvent.VK_S:%0A
             ship
@@ -1575,32 +1575,60 @@
 yEvent.VK_LEFT:%0A
+        case KeyEvent.VK_A:%0A
             ship
@@ -1688,32 +1688,60 @@
 Event.VK_RIGHT:%0A
+        case KeyEvent.VK_D:%0A
             ship
@@ -1799,32 +1799,60 @@
 KeyEvent.VK_UP:%0A
+        case KeyEvent.VK_W:%0A
             ship
@@ -1882,32 +1882,32 @@
          break;%0A
-
         case Key
@@ -1913,32 +1913,60 @@
 yEvent.VK_DOWN:%0A
+        case KeyEvent.VK_S:%0A
             ship

Add WASD controls.