-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.pde
65 lines (51 loc) · 1.36 KB
/
Node.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
abstract class Node {
public boolean alive;
public long birthTick;
public PVector origin;
public PVector[] boundingBox;
Node() {
this.alive = false;
this.birthTick = -1L;
this.origin = new PVector(0, 0);
this.boundingBox = new PVector[]{ new PVector(0, 0), new PVector(0, 0) };
}
void spawn() {
this.alive = true;
this.birthTick = levels.getCurrent().currentTick;
}
void delete() {
this.alive = false;
}
long getTicksAlive() {
return levels.getCurrent().currentTick - this.birthTick;
}
PVector[] getBoundingBoxForRadius(float radius) {
PVector mins = this.origin.copy().sub(radius, radius);
PVector maxs = this.origin.copy().add(radius, radius);
return new PVector[]{ mins, maxs };
}
PVector[] getBoundingBoxForRect(float width, float height) {
PVector mins = this.origin.copy().sub(width / 2.0, height / 2.0);
PVector maxs = this.origin.copy().add(width / 2.0, height / 2.0);
return new PVector[]{ mins, maxs };
}
abstract void updateBoundingBox();
void drawBoundingBox() {
push();
rectMode(CORNERS);
noFill();
stroke(60, 1.0, 0.9);
strokeWeight(2);
rect(this.boundingBox[0].x, this.boundingBox[0].y, this.boundingBox[1].x, this.boundingBox[1].y);
pop();
}
void OnTick() {}
void OnDraw() {}
void OnDrawInternal() {
push();
this.OnDraw();
pop();
if (DRAW_BOUNDING_BOXES)
this.drawBoundingBox();
}
}