-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWalker.pde
More file actions
124 lines (83 loc) · 1.75 KB
/
Copy pathWalker.pde
File metadata and controls
124 lines (83 loc) · 1.75 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
class Walker {
PVector loc;
ArrayList<PVector> path;
Walker() {
loc = new PVector(0, 0);
path = new ArrayList<PVector>();
}
void display() {
stroke(0);
fill(175);
rectMode(CENTER);
rect(loc.x, loc.y, 25, 25);
beginShape();
stroke(0);
noFill();
for (PVector v: path) {
vertex(v.x, v.y);
}
endShape();
}
void walk() {
boolean r, l, u, d;
r = true;
l = true;
u = true;
d = true;
for (int i = 0; i < path.size(); i++) {
PVector temppath = path.get(i);
if (loc.x + 20 == temppath.x && loc.y == temppath.y || loc.x +20 > width) {
r =false;
}
if (loc.x -20 == temppath.x && loc.y == temppath.y || loc.x - 20 < 0 ) {
l = false;
}
if (loc.y +20 == temppath.y && loc.x == temppath.x || loc.y +20 > height) {
d = false;
}
if (loc.y - 20 == temppath.y && loc.x == temppath.x || loc.y -20 < 0) {
u = false;
}
println("right " + r );
println("left " + l );
println("up " + u );
println("down " + d );
}
int rand = int(random(0, 4));
switch(rand) {
case 0:
if (r) {
loc.x +=20;
}
break;
case 1:
if (l) {
loc.x -= 20;
}
break;
case 2:
if (d) {
loc.y +=20;
}
break;
case 3:
if (u) {
loc.y -= 20;
}
break;
}
if(!r && !d && !u && !l){
for(int i = path.size()-1; i >= 0; i--){
// PVector tpath = path.get(i);
// tpath.x = 0;
// tpath.y= 0;
path.remove(i);
}
loc.x = 0;
loc.y = 0;
}
loc.x = constrain(loc.x, 0, width);
loc.y = constrain(loc.y, 0, height);
path.add(loc.get());
}
}