-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameKeyListener.java
49 lines (37 loc) · 1.17 KB
/
GameKeyListener.java
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
import java.awt.event.*;
public class GameKeyListener implements KeyListener{
static int count;
public GameKeyListener(){
GameScreen.gameFrame.addKeyListener(this);
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
if(GameFunctions.keyLimit== false){
if (key == KeyEvent.VK_RIGHT) {
GameFunctions.dirX = 20;
presedAction();
} else if (key == KeyEvent.VK_LEFT) {
GameFunctions.dirX = -20;
presedAction();
} else if (key == KeyEvent.VK_DOWN) {
GameFunctions.dirY = 20;
presedAction();
} else if (key == KeyEvent.VK_UP) {
GameFunctions.dirY = -20;
presedAction();
}
}
}
public void presedAction(){
GameFunctions.moving=true;
GameFunctions.keyLimit = true;
GameFunctions.playSound("move");
}
@Override
public void keyReleased(KeyEvent e) {
}
}