-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExplosion.pde
81 lines (67 loc) · 1.67 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
public class Explosion
{
float x,y;
float w = 120;
float h = 120;
float lifeTime = 0;
ArrayList<Smoke> smokeList = new ArrayList<Smoke>();
AudioPlayer explosionSound;
public Explosion(float x1, float y1)
{
x=x1;
y=y1;
explosionSound = minim.loadFile("Sounds/Explosion.mp3");
playExplosionSound();
}
public void display()
{
if (lifeTime <= 6)
{
String filename = "Explosion/frame_" + (int)lifeTime + "_delay-0.1s.png";
PImage img = loadImage(filename);
image(img,x+OFFSETX,y+OFFSETY,w,h);
drawSmoke(x, y, 25);
lifeTime+=0.2;
}
updateSmokeList();
}
void drawSmoke(float centerX, float centerY, float R)
{
float r = R * sqrt(random(0,1));
float theta = random(0,1) * 2 * PI;
float x = centerX + r * cos(theta);
float y = centerY + r * sin(theta);
float opacity = random(120,180);
float smokeRadius = random(10,30);
if (smokeList.size()< 20 && frameCount%3==0)
{
smokeList.add(new Smoke(x, y, smokeRadius, opacity, theta));
}
}
void updateSmokeList()
{
for (int i = 0; i < smokeList.size(); i++) //update tank class to same double loop smoke removal system
{
Smoke smoke = smokeList.get(i);
smoke.display();
}
for (int i = 0; i < smokeList.size(); i++)
{
Smoke smoke = smokeList.get(i);
if (smoke.opacity < 10)
{
smokeList.remove(i);
}
}
}
public float generateOffset()
{
float r = 6-lifeTime;
float offset = random(0, r*1.8);
return offset;
}
void playExplosionSound()
{
explosionSound.play();
}
}