public void keyReleased(KeyEvent arg0) { String key = "" + ("" + arg0.getKeyChar()).toLowerCase(); if (key.equals("a")) { // move to the left player.stop(); } if (key.equals("d")) { // move to the right player.stop(); } }
public void keyPressed(KeyEvent arg0) { // the controller should not do anything when the player is dead if (player.getLives() <= 0) { return; } String key = ("" + arg0.getKeyChar()).toLowerCase(); if (key.equals("a")) { // move to the left player.moveLeft(); } if (key.equals("d")) { // move to the right player.moveRight(); } if (key.equals(" ")) { // shoot player.fire(); } }