Merge branch 'master' of github.com:teamteamteam/SpaceScooter

This commit is contained in:
lubiana 2014-10-28 13:44:42 +01:00
commit a9bbc264eb
3 changed files with 8 additions and 7 deletions

BIN
res/images/ship.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 370 B

After

Width:  |  Height:  |  Size: 375 B

View File

@ -2,25 +2,26 @@ package de.teamteamteam.spacescooter.control;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.KeyListener; import java.awt.event.KeyListener;
import java.util.ArrayList;
public class Keyboard implements KeyListener { public class Keyboard implements KeyListener {
private static boolean[] keys = new boolean[150]; //TODO: This might kill the game in case there are keycodes > 150 private static ArrayList<Integer> activeKeys = new ArrayList<Integer>();
public static boolean isKeyDown(int keyCode) { public static boolean isKeyDown(int keyCode) {
if (keyCode >= 0 && keyCode < keys.length) { return Keyboard.activeKeys.contains((Integer) keyCode);
return keys[keyCode];
}
return false;
} }
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
keys[e.getKeyCode()] = true; if(Keyboard.activeKeys.contains((Integer) e.getKeyCode())) return;
Keyboard.activeKeys.add((Integer) e.getKeyCode());
} }
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
keys[e.getKeyCode()] = false; if(Keyboard.activeKeys.contains((Integer) e.getKeyCode())) {
Keyboard.activeKeys.remove((Integer) e.getKeyCode());
}
} }
public void keyTyped(KeyEvent e) { public void keyTyped(KeyEvent e) {