-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExplosion.cpp
76 lines (62 loc) · 1.35 KB
/
Explosion.cpp
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
#include "Explosion.h"
Explosion::Explosion(int force)
{
mForce = force;
}
Explosion::~Explosion()
{
mForce = 0;
}
void Explosion::tick()
{
bool particlesDone;
Particle* particles = getParticles();
if (isActive()) {
//if (SDL_GetTicks() - getStartTime() > PARTICLE_LIFE_TIME) {
//stop();
//}
particlesDone = true;
for (int p = 0; p < MAX_PARTICLES; p++) {
//if (SDL_GetTicks() - particles[p].getStartTime() > PARTICLE_LIFE_TIME) {
//particles[p].setAlpha(0);
//}
particles[p].move();
//if (particles[p].getForce() > 1) {
//particlesDone = false;
//}
if (particles[p].getAlpha() > 0) {
particlesDone = false;
}
}
if (particlesDone) {
stop();
}
}
}
void Explosion::reset()
{
SDL_Rect r;
SDL_Color c;
Particle* particles = getParticles();
printf("reset particle emitter %d at pos x %d y %d\n", getInstNum(), getXPos(), getYPos());
for (int i = 0; i < MAX_PARTICLES; i++) {
r.x = getXPos();
r.y = getYPos();
r.w = (rand() % MAX_PARTICLE_SIZE) + 1;
r.h = r.w;
c.r = rand() % 0xFF;
c.g = rand() % 0xFF;
c.b = rand() % 0xFF;
c.a = 0xFF;
particles[i].setRect(r);
particles[i].setImpulse(rand() % 360, mForce * (double)(1 / (double)r.w));
particles[i].setColor(c);
particles[i].resetTime();
}
setActive(true);
resetStartTime();
}
void Explosion::setForce(int force)
{
mForce = force;
}