/
ModuleParticles.cpp
148 lines (117 loc) · 3.75 KB
/
ModuleParticles.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
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
#include "ModuleParticles.h"
#include "Application.h"
#include "ModuleTextures.h"
#include "Directions.h"
#include "ModuleCollisions.h"
#include "ModulePlayer.h"
#include "SoundLibrary.h"
#include "SDL/include/SDL.h"
ModuleParticles::ModuleParticles()
{
}
ModuleParticles::~ModuleParticles(){
for (vector<Particle*>::iterator it = particles.begin(); it != particles.end(); ++it)
RELEASE(*it);
particles.clear();
}
bool ModuleParticles::CleanUp(){
for (int i = 0; i < particles.size(); i++)
{
App->textures->Unload(particles[i]->graphics);
}
return true;
}
update_status ModuleParticles::Update(){
Uint32 time = SDL_GetTicks();
for (int i = 0; i < particles.size(); i++){
if (particles[i]->duration != -1 && particles[i]->begun + particles[i]->duration <= time){
particles[i]->MarkForDead();
}
else {
particles[i]->Update();
}
}
return UPDATE_CONTINUE;
}
update_status ModuleParticles::PostUpdate(){
//Deletes colliders marked for it
std::vector<std::string>::size_type i = 0;
while (i < particles.size()) {
if (particles[i]->isMarkedForDead()) {
delete particles[i];
particles.erase(particles.begin() + i);
}
else {
++i;
}
}
return UPDATE_CONTINUE;
}
void ModuleParticles::AddParticles(Particle* particle){
particles.push_back(particle);
}
Projectile* ModuleParticles::CreateProjectile(const projectile_type type, const fPoint position, const Facing facing, SDL_Texture* graphics, ModulePlayer* sender){
//Creates the projectile
Projectile* projectile = new Projectile({ position.x, position.y }, graphics);
projectile->collider = App->collisions->AddCollider(COLLIDER_PROJECTILE, { position.x, position.y, 16, 16 }, projectile);
projectile->duration = 10000;
projectile->projectileType = type;
int dirH, dirV;
switch (facing)
{
case UP: dirH = 0; dirV = -1; break;
case UPRIGHT: dirH = 1; dirV = -1; break;
case RIGHT: dirH = 1; dirV = 0; break;
case DOWNRIGHT: dirH = 1; dirV = 1; break;
case DOWN: dirH = 0; dirV = 1; break;
case DOWNLEFT: dirH = -1; dirV = 1; break;
case LEFT: dirH = -1; dirV = 0; break;
case UPLEFT: dirH = -1; dirV = -1; break;
default: dirH = 0; dirV = -1; break;
}
projectile->speed = { dirH * 4, dirV * 4 };
//Does the throw animation
projectile->animation = new Animation();
int dim = 18 - 2; //Dimension. Tilesize - (border*2). Both width and height.
switch (type)
{
case PROJECTILE_WARRIOR: {
int yValue = (18 * 9) + 1; //(Tilesize * line) + border
for (int i = 0; i < 8; i++){
//Xvalue = Tilesize * ( column + animationStep ) + border
projectile->animation->frames.push_back({ 18 * (24 + i) + 1, yValue, dim, dim });
}
projectile->animation->speed = 0.5f;
App->soundLib->playSound(SOUND_WARRIOR_ATTACK);
break;
}
case PROJECTILE_VALKYRIE: {
int firstImage = 10 * 44 + 17;
projectile->animation->frames.push_back({ (18 * ((firstImage + facing) % 44)) + 1, (18 * ((firstImage + facing) / 44)) + 1, dim, dim });
projectile->animation->speed = 0.0f;
App->soundLib->playSound(SOUND_VALKYRIE_ATTACK);
break;
}
case PROJECTILE_WIZARD:{
int firstImage = 11 * 44 + 10;
projectile->animation->frames.push_back({ (18 * ((firstImage + facing) % 44)) + 1, (18 * ((firstImage + facing) / 44)) + 1, dim, dim });
projectile->animation->speed = 0.0f;
App->soundLib->playSound(SOUND_WIZARD_ATTACK);
break;
}
case PROJECTILE_ELF: {
int firstImage = 12 * 44 + 3;
projectile->animation->frames.push_back({ (18 * ((firstImage + facing) % 44)) + 1, (18 * ((firstImage + facing) / 44)) + 1, dim, dim });
projectile->animation->speed = 0.0f;
App->soundLib->playSound(SOUND_ELF_ATTACK);
break;
}
default:
break;
}
projectile->damage = 12 * 3;
if (sender != nullptr){
projectile->sender = sender;
}
return projectile;
}