-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyboard.java
More file actions
executable file
·60 lines (52 loc) · 1.36 KB
/
Keyboard.java
File metadata and controls
executable file
·60 lines (52 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.KeyEvent.*;
/**
* Takes keybord input and uses it to control spaceship in window which is passes as a parameter.
*
* @author Dexter Antonio
* @version 5/01/13
*/
public class Keyboard implements KeyListener
{
GameWindow window;
public Keyboard(GameWindow window){
this.window = window;
}
public void keyPressed(KeyEvent e){
int key = e.getKeyCode();
if(key == KeyEvent.VK_LEFT){
window.setRotateLeft(true);
}
if(key == KeyEvent.VK_RIGHT){
window.setRotateRight(true);
}
if(key == KeyEvent.VK_UP){
window.setThrust(true);
}
if(key == KeyEvent.VK_SPACE){
window.fireMissile();
}
}
public void keyReleased(KeyEvent e){
int key = e.getKeyCode();
if(key == KeyEvent.VK_LEFT){
window.setRotateLeft(false);
}
if(key == KeyEvent.VK_RIGHT){
window.setRotateRight(false);
}
if(key == KeyEvent.VK_UP){
window.setThrust(false);
}
if(key == KeyEvent.VK_R){
window.respawn();
}
if(key == KeyEvent.VK_A){
window.transportSpaceship();
}
}
public void keyTyped(KeyEvent e){
}
}