-
Notifications
You must be signed in to change notification settings - Fork 0
/
PacmanGrid.pde
114 lines (89 loc) · 2.37 KB
/
PacmanGrid.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
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
import peasy.*;
import java.net.URL;
import java.net.URISyntaxException;
final int WIDTH = 1920;
final int HEIGHT = 1080;
final int GRID_SIZE = 4;
final int GRID_SCALE = 100;
final boolean GRID_FLAT = true;
PeasyCam camera;
Grid grid = new Grid(GRID_SIZE, GRID_SCALE, GRID_FLAT);
Pacman pacman;
Ghost[] ghosts = new Ghost[int(pow(GRID_SIZE, GRID_FLAT ? 2 : 3)) / 10];
boolean drawGhosts = true;
boolean drawFill = true;
boolean drawWalls = true;
boolean pause = true;
boolean record = false;
int recordingNumber = getStartFolder();
void settings() {
size(WIDTH, HEIGHT, P3D);
}
CellIndex randomLocation() {
int x = int(random(0, GRID_SIZE));
int y = int(random(0, GRID_SIZE));
int z = GRID_FLAT ? 0 : int(random(0, GRID_SIZE));
return new CellIndex(x, y, z);
}
void setup() {
float centre = (GRID_SCALE * GRID_SIZE) / 2;
camera = new PeasyCam(this, centre, centre, GRID_FLAT ? 0 : centre, 1000);
for (int i = 0; i < ghosts.length; i++) {
ghosts[i] = new Ghost(grid, randomLocation());
}
pacman = new Pacman(grid, randomLocation(), ghosts);
}
void keyPressed() {
if (key == 'g') {
drawGhosts = !drawGhosts;
}
if (key == 'w') {
drawWalls = !drawWalls;
}
if (key == 'f') {
drawFill = !drawFill;
}
if (key == 'p' || key == ' ') {
pause = !pause;
}
if (key == 'r') {
record = !record;
if (!record) {
recordingNumber++;
}
}
}
int getStartFolder() {
int recordingNumber = 1;
try {
URL url = getClass().getResource("PacmanGrid.class");
String[] pathSegments = url.toURI().getPath().split("/");
//....../out/PacmanGrid.class
String path = String.join("\\", Arrays.copyOfRange(pathSegments, 1, pathSegments.length - 2));
File file = new File(path + "\\render\\" + Integer.toString(recordingNumber));
while(file.exists()) {
recordingNumber++;
file = new File(path + "\\render\\" + Integer.toString(recordingNumber));
}
} catch(URISyntaxException exception) {}
return recordingNumber;
}
void draw() {
background(0, 0, 0, 1);
grid.draw(drawWalls, drawFill);
for (int i = 0; i < ghosts.length; i++) {
if (!pause) {
ghosts[i].move();
}
if (drawGhosts) {
ghosts[i].draw();
}
}
if (!pause) {
pacman.move();
}
pacman.draw();
if (record) {
saveFrame("render\\" + recordingNumber + "\\pacman-####.png");
}
}