-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGas.pde
54 lines (47 loc) · 1.47 KB
/
Gas.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
// gas grenade
class Gas {
PVector myPosition;
PVector[] circles = new PVector[3];
float alpha = 255;
boolean completed = false;
int maxSize;
int size = 1;
Gas (float x, float y, int max) {
myPosition = new PVector(x, y);
maxSize = max;
for (int i = 0; i < circles.length; i++) {
circles[i] = new PVector();
circles[i].set((myPosition.x + random(-50, 50)), myPosition.y + random(-50, 50));
}
}
boolean isComplete() {
return completed;
}
void update() {
if (size <= maxSize) {
size++;
}
// loops through the gas circles and checks for emus inside, if so, damages them with no bleeding
for (int i = 0; i < circles.length; i++) {
for (Emu e : emus) {
if (e.getX() > circles[i].x - size/2 && e.getX() < circles[i].x + size/2 && e.getY() > circles[i].y - size/2 && e.getY() < circles[i].y + size/2) {
if (frameCount%40 == 0) {
e.reduceHP(5, false);
}
}
}
// draws the gas circles
fill(252, 205, 33, alpha);
ellipse(circles[i].x, circles[i].y, size, size);
// moves circles slightly to give them a more gaseous effect
circles[i].x += random(-1, 1);
circles[i].y += random(-1, 1);
}
// reduces alpha, making gas more transparent
alpha -= 0.4;
// when gas has dissipated, sets completed flag so the gas object will be removed on the next frame.
if (alpha <= 0) {
completed = true;
}
}
}