-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleParticles.cpp
More file actions
159 lines (126 loc) · 3.83 KB
/
ModuleParticles.cpp
File metadata and controls
159 lines (126 loc) · 3.83 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <math.h>
#include "ModuleParticles.h"
#include "Application.h"
#include "ModuleAudio.h"
#include "ModuleTextures.h"
#include "ModuleRender.h"
#include "ModuleCollision.h"
#include "SDL/include/SDL_timer.h"
ModuleParticles::ModuleParticles()
{}
ModuleParticles::~ModuleParticles()
{}
// Load assets
bool ModuleParticles::Start()
{
LOG("Loading particles");
graphics = App->textures->LoadWithColorKey("Resources/Images/Level/General_Sprites.png", 0xBA, 0xFE, 0xCA);
// TODO 2: Create a prototype for the laser particle
// audio: rtype/laser.wav
// coords: {232, 103, 16, 12}; {249, 103, 16, 12};
water = new Particle();
water->typeParticle = WATER;
water->anim.frames.push_back({ 815, 760, 28, 23 });
water->anim.frames.push_back({ 854, 760, 32, 24 });
water->anim.frames.push_back({ 912, 760, 32, 24 });
water->anim.speed = 0.2f;
water->anim.loop = false;
//fxWater = App->audio->LoadFx("Resources/Music/nitro.wav");
dust = new Particle();
dust->typeParticle = DUST;
dust->anim.frames.push_back({ 14, 751, 32, 32 });
dust->anim.frames.push_back({ 64, 752, 32, 32 });
dust->anim.frames.push_back({ 112, 752, 32, 32 });
dust->anim.frames.push_back({ 160, 752, 32, 32 });
dust->anim.frames.push_back({ 208, 752, 32, 32 });
dust->anim.frames.push_back({ 253, 752, 32, 32 });
dust->anim.frames.push_back({ 300, 752, 32, 32 });
dust->anim.frames.push_back({ 346, 752, 32, 32 });
dust->anim.speed = 0.3f;
dust->anim.loop = false;
fxDust = App->audio->LoadFx("Resources/Music/nitro.wav");
// TODO 12: Create a new "Explosion" particle
// audio: rtype/explosion.wav
// coords: {274, 296, 33, 30}; {313, 296, 33, 30}; {346, 296, 33, 30}; {382, 296, 33, 30}; {419, 296, 33, 30}; {457, 296, 33, 30};
return true;
}
// Unload assets
bool ModuleParticles::CleanUp()
{
LOG("Unloading particles");
App->textures->Unload(graphics);
for (list<Particle*>::iterator it = active.begin(); it != active.end(); ++it)
RELEASE(*it);
active.clear();
return true;
}
// PreUpdate to clear up all dirty particles
update_status ModuleParticles::PreUpdate()
{
for (list<Particle*>::iterator it = active.begin(); it != active.end();)
{
if ((*it)->to_delete == true)
{
RELEASE(*it);
it = active.erase(it);
}
else
++it;
}
return UPDATE_CONTINUE;
}
// Update all particle logic and draw them
update_status ModuleParticles::Update()
{
for (list<Particle*>::iterator it = active.begin(); it != active.end(); ++it)
{
Particle* p = *it;
p->Update();
App->renderer->Blit(graphics, p->position.x, p->position.y, &(p->anim.GetCurrentFrame()));
// Handle particle fx here ?
}
return UPDATE_CONTINUE;
}
void ModuleParticles::AddWaterParticle(const Particle& p, int x, int y)
{
bool containWater = false;
for (list<Particle*>::iterator it = active.begin(); it != active.end(); ++it) {
if ((*it)->typeParticle == WATER)
{
containWater = true;
}
}
if (!containWater) {
Particle* newParticle = new Particle(p);
newParticle->position = { x,y };
active.push_back(newParticle);
//App->audio->PlayFx(fxparticle);
}
}
void ModuleParticles::AddDustParticle(const Particle & particle, int x, int y)
{
Particle* newParticle = new Particle(particle);
newParticle->position = { x,y };
active.push_back(newParticle);
App->audio->PlayFx(fxDust);
}
// -------------------------------------------------------------
// -------------------------------------------------------------
Particle::Particle()
{}
// TODO 3: Fill in a copy constructor
Particle::Particle(const Particle& p) : anim(p.anim), position(p.position), speed(p.speed), typeParticle(p.typeParticle)
{}
Particle::~Particle()
{
}
void Particle::Update()
{
// TODO 5: This is the core of the particle logic
// draw and audio will be managed by ModuleParticle::Update()
// Note: Set to_delete to true is you want it deleted
if (this->anim.Finished())
{
this->to_delete = true;
}
}