-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.pde
57 lines (51 loc) · 1.15 KB
/
control.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
void keyPressed() {
// change treshhold
int t = tracker.getThreshold();
if (key == 'z') {
t+=5;
tracker.setThreshold(t);
} else if (key == 'x') {
t-=5;
tracker.setThreshold(t);
}
// mode Pac-Man with keyboard
if (pac.moving) {
if (key == CODED) {
if (keyCode == UP) {
pac.moveRequested = 1;
} else if (keyCode == RIGHT) {
pac.moveRequested = 2;
} else if (keyCode == DOWN) {
pac.moveRequested = 3;
} else if (keyCode == LEFT) {
pac.moveRequested = 4;
}
}
}
if ((key == '.') || (key == ' ')) {
if (paused == 0) {
paused = 1;
redraw();
} else {
paused = 0;
redraw();
}
}
}
void move() {
// draw the raw location
PVector v1 = tracker.getPos();
fill(255,255,255);
noStroke();
ellipse(v1.x,v1.y,20,20);
// choose direction
if (v1.x < (width/3)) {
pac.moveRequested = 4; // left
} else if (v1.x > ((width/3)*2)) {
pac.moveRequested = 2; // right
} else if (v1.y < (height/3)) {
pac.moveRequested = 1; // up
} else if (v1.y > ((height/3)*2)) {
pac.moveRequested = 3; // down
}
}