-
Notifications
You must be signed in to change notification settings - Fork 1
/
SteeringChase.pde
56 lines (44 loc) · 990 Bytes
/
SteeringChase.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
public static int VEHICLE_NUMBER = 100;
public ArrayList<Prey> preys;
public Predator predator;
public boolean debug = false;
void setup() {
fullScreen();
preys = new ArrayList<Prey>();
predator = new Predator(random(0, width), random(0, height));
fillPreys();
}
void draw() {
background(0);
for (Vehicle v : preys) {
v.update();
v.display();
}
predator.update();
trimDead();
}
public void trimDead() {
for (int i = 0; i < preys.size(); i++) {
if (preys.get(i).isDead()) {
preys.remove(i);
}
}
}
public void fillPreys() {
for (int i = 0; i < VEHICLE_NUMBER; i++) {
preys.add(new Prey(random(0, width), random(0, height)));
}
predator.setPrey(preys.get((int)random(0, preys.size())));
}
void keyPressed() {
switch(key) {
case 'D':
debug = !debug;
println("Debug mode");
break;
case 'd':
debug = !debug;
println("Debug mode");
break;
}
}