-
Notifications
You must be signed in to change notification settings - Fork 0
/
Formation.pde
43 lines (33 loc) · 1010 Bytes
/
Formation.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
class Formation {
PVector position;
Cell cells[];
Formation formations[];
Formation(Cell c[]) {
cells = c;
}
Formation(Cell c[], Formation f[]) {
cells = c;
formations = f;
}
Formation(Formation f[]) {
formations = f;
}
void drawFormation(PVector l) { //Relative to top-right corner
if (formations != null) {
for (int i = 0; i < formations.length; i++) {
formations[i].drawFormation(new PVector((l.x + i) * formations[i].cells.length, l.y));
}
}
if (cells != null) {
for (int i = 0; i < cells.length; i++) {
PVector worldLoc = relativeToWorldLocation(l, cells[i].position);
if (!grid.inBounds(worldLoc)) continue;
grid.fillCell(new PVector(worldLoc.x, worldLoc.y), 0);
liveCell[(int)worldLoc.x][(int)worldLoc.y] = true;
}
}
}
PVector relativeToWorldLocation(PVector w, PVector r) {
return new PVector(w.x + r.x, w.y + r.y);
}
}