-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ghost.pde
54 lines (43 loc) · 1.39 KB
/
Ghost.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
import java.util.Deque;
import java.util.Collection;
import java.util.Map;
import java.util.HashMap;
class Ghost extends Agent {
float hue = random(150, 255);
Ghost(Grid _grid, CellIndex start) {
super(_grid, start);
speed = 3 * random(1, 1.2);
}
protected void updateTarget() {
CellIndex lastTarget = target;
ArrayList<CellIndex> targetCells = grid.getAdjacentCells(lastTarget);
// Prefer maintaining the current direction.
// If that's not possible, pick a direction at random.
if (currentDirection != null && random(1) > 0.5) {
Optional<CellIndex> sameDirectionCell = grid.getAdjacentCell(lastTarget, currentDirection);
if (sameDirectionCell.isPresent()) {
setTarget(sameDirectionCell.get());
return;
}
}
setTarget(targetCells.get(int(random(targetCells.size()))));
}
protected void drawAgent() {
noStroke();
colorMode(HSB);
for (int i = 0; i < 50; i++) {
fill(hue * random(0.9, 1.2), 200, 200, 50);
pushMatrix();
rotateX(random(TWO_PI));
rotateY(random(TWO_PI));
rotateZ(random(TWO_PI));
translate(random( -(cellSize / 5),(cellSize / 5)), 0, 0);
sphere(cellSize / 30);
popMatrix();
}
colorMode(RGB);
}
protected void updateVisitedCellColour() {
grid.cells[target.x][target.y][target.z].updateColour(hue, 5);
}
}