-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPowerUp.pde
111 lines (100 loc) · 2.32 KB
/
PowerUp.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
public class PowerUp
{
String type = "";
float x;
float y;
PImage img;
float lifeTime = 0;
ArrayList<Smoke> smokeList = new ArrayList<Smoke>();
float radAngle=0;
AudioPlayer spawnSound;
AudioPlayer collectSound;
public PowerUp(float x2, float y2, int typeNum)
{
x = x2;
y = y2;
if (typeNum == 0)
{
type = "Machine Gun";
} else if (typeNum == 1)
{
type = "Shotgun";
} else if (typeNum == 2)
{
type = "Laser";
} else if (typeNum == 3)
{
type = "Missle";
} else if (typeNum == 4)
{
type = "Beam";
} else if (typeNum == 5)
{
type = "Frag Bomb";
}
img = loadImage("Power Ups/"+type+".png");
spawnSound = minim.loadFile("Sounds/Powerup Spawn.mp3");
collectSound = minim.loadFile("Sounds/Powerup Collect.mp3");
radAngle = random(-.4, .4)*PI/2;
}
public void display()
{
float size = 1;
if (6 <= lifeTime && lifeTime <= 8)
{
drawSmoke(x, y, 10);
}
if (lifeTime < 4)
{
size = 0.7/4*lifeTime+.5;
} else if (lifeTime < 6)
{
size = -0.2/2*(lifeTime-4)+1.2;
}
lifeTime+=0.2;
updateSmokeList();
pushMatrix();
translate(x+OFFSETX, y+OFFSETY);
rotate(radAngle);
scale(size);
image(img, 0, 0);
popMatrix();
}
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, 20);
if (smokeList.size()< 10 && frameCount%2==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.displaySmoke();
}
for (int i = 0; i < smokeList.size(); i++)
{
Smoke smoke = smokeList.get(i);
if (smoke.opacity < 10)
{
smokeList.remove(i);
}
}
}
void playSpawnSound()
{
spawnSound.play();
}
void playCollectSound()
{
collectSound.play();
}
}