-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathKeyHandler.pde
More file actions
38 lines (38 loc) · 1.06 KB
/
KeyHandler.pde
File metadata and controls
38 lines (38 loc) · 1.06 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
class KeyHandler{
int[] KEYS = {65,87,68,83,32,16,10,67,89,84,85};
int LEN = KEYS.length;
boolean[] keysDown = new boolean[LEN];
public KeyHandler(){
for(int i = 0; i < LEN; i++){
keysDown[i] = false;
}
}
void handle(int k, boolean state){
for(int i = 0; i < LEN; i++){
if(KEYS[i] == k){
keysDown[i] = state;
}
if(i == 6 && KEYS[i] == k && state){ // ENTER to toggle mouse lock
TRAP_MOUSE = !TRAP_MOUSE;
r.confinePointer(TRAP_MOUSE);
r.setPointerVisible(!TRAP_MOUSE);
}
if(i == 7 && KEYS[i] == k && state){
followSpecimen = !followSpecimen;
}
if(i == 9 && KEYS[i] == k && state && followSpecimen){
if(closest_AI.target != null && getSpeciesType(closest_AI.target.species) >= 1){
closest_AI = closest_AI.target;
}
}
}
}
boolean keysToAction(int n){
if(n <= 4){ // WASD and space
return keysDown[n];
}else if(n == 7){ // wandering
return keysDown[8];
}
return false;
}
}