-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExplosion.pde
61 lines (53 loc) · 1.63 KB
/
Explosion.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
class Explosion {
float myX, myY, myRadius;
int frameNum = 1;
boolean completed;
PImage myExplosion[] = new PImage[25];
Explosion(float x, float y, float radius) {
myX = x;
myY = y;
myRadius = radius;
// loads explosion sprites and resizes them according to the radius
for (int i = 1; i < myExplosion.length; i++) {
myExplosion[i] = explosionAnimation[i].copy();
myExplosion[i].resize((int) (myRadius * 3), (int) (myRadius * 3));
}
explosionSound.rewind();
explosionSound.play();
}
void setX(float x) {
myX = x;
}
void setY(float y) {
myY = y;
}
boolean isComplete() {
return completed;
}
void update () {
if (!completed) {
// damages (likely kills) all emus in the explosion radius
for (Emu e : emus) {
if (e.getX() > myX - myRadius && e.getX() < myX + myRadius && e.getY() > myY - myRadius && e.getY() < myY + myRadius) {
// exploded boolean to make sure the emu takes damage from the explosion only once instead of every frame of the explosion
if (!e.getExploded()) {
e.setExploded(true);
e.reduceHP(500);
}
}
}
// damages truck if near the explosion
if (truck.getX() > myX - myRadius && truck.getX() < myX + myRadius && truck.getY() > myY - myRadius && truck.getY() < myY + myRadius) {
truck.reduceHP(0.001);
}
// animates explosion
if (frameCount%2 == 0) {
frameNum++;
if (frameNum >= myExplosion.length - 1) {
completed = true;
}
}
image(myExplosion[frameNum], myX, myY);
}
}
}