-
Notifications
You must be signed in to change notification settings - Fork 1
/
Controller.pde
69 lines (61 loc) · 1.26 KB
/
Controller.pde
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
61
62
63
64
65
66
67
68
69
class Controller {
Player plr;
PlayerScript pScript;
int W=0;
int A = 1;
int S = 2;
int D = 3;
int UP = 0;
int LEFT = 1;
int DOWN = 2;
int RIGHT = 3;
int LEFTDIR = -1;
int RIGHTDIR = 1;
boolean[] buttons;
Controller(Player player) {
buttons = new boolean[4];
this.plr = player;
this.pScript = (PlayerScript) plr.player.getComponent("PlayerScript");
}
void update() {
if (buttons[W]) {
pScript.jump();
}
if (buttons[A]) {
pScript.walk(LEFTDIR);
}
if (buttons[D]) {
pScript.walk(RIGHTDIR);
}
}
}
//Please Note that these functions are OUTSIDE the class
void keyPressed() {
println("pushing button");
if (key == 'w') {
controller.buttons[controller.W] = true;
}
if (key == 'a') {
controller.buttons[controller.A] = true;
}
if (key == 's') {
controller.buttons[controller.S] = true;
}
if (key == 'd') {
controller.buttons[controller.D] = true;
}
}
void keyReleased() {
if (key == 'w') {
controller.buttons[controller.W] = false;
}
if (key == 'a') {
controller.buttons[controller.A] = false;
}
if (key == 's') {
controller.buttons[controller.S] = false;
}
if (key == 'd') {
controller.buttons[controller.D] = false;
}
}