-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleParticles.h
137 lines (105 loc) · 3.42 KB
/
ModuleParticles.h
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
#pragma once
#ifndef __MODULEPARTICLES_H__
#define __MODULEPARTICLES_H__
#include "Application.h"
#include "Animation.h"
#include "p2Point.h"
#include "Module.h"
#include "SDL.h"
#include "ModuleCollisions.h"
#define MAX_ACTIVE_PARTICLES 200
struct SDL_Texture;
struct Collider;
struct Particle
{
public:
// Constructor
Particle();
// Copy constructor
Particle(const Particle& p);
~Particle();
// Called in ModuleParticles' Update
// Handles the logic of the particle
// Returns false when the particle reaches its lifetime
bool Update();
public:
// Defines the position in the screen
iPoint position;
// Defines the speed at which the particle will move (pixels per second)
iPoint speed;
// A set of rectangle sprites
Animation anim;
// Defines wether the particle is alive or not
// Particles will be set to not alive until "spawnTime" is reached
bool isAlive = false;
// Defines the time when the particle will be spawned
int frameCount = 0;
// Defines the total amount of time during which the particle will be active (in miliseconds)
Uint32 lifetime = 0;
// The particle's collider
Collider* collider = nullptr;
bool isWeapon = false;
};
class ModuleParticles : public Module
{
public:
// Constructor
// Initializes all the particles in the array to nullptr
ModuleParticles(bool startEnabled);
//Destructor
~ModuleParticles();
// Called when the module is activated
// Loads the necessary textures for the particles
bool Start() override;
// Called at the middle of the application loop
// Iterates all the particles and calls its Update()
// Removes any "dead" particles
update_status Update() override;
// Called at the end of the application loop
// Iterates all the particles and draws them
update_status PostUpdate() override;
// Called on application exit
// Destroys all active particles left in the array
bool CleanUp() override;
// Called when a particle collider hits another collider
void OnCollision(Collider* c1, Collider* c2) override;
// Creates a new particle and adds it to the array
// Param particle - A template particle from which the new particle will be created
// Param x, y - Position x,y in the screen (upper left axis)
// Param delay - Delay time from the moment the function is called until the particle is displayed in screen
void AddParticle(const Particle& particle, int x, int y, Collider::Type colliderType = Collider::Type::NONE, uint delay = 0);
inline uint GetParticlesCount() const { return particlesCount; };
private:
// Particles spritesheet loaded into an SDL Texture
SDL_Texture* particlesTexture = nullptr;
// An array to store and handle all the particles
Particle* particles[MAX_ACTIVE_PARTICLES] = { nullptr };
// An index to the last added particle
uint lastParticle = 0;
// Total amount of particles loaded into the array
uint particlesCount = 0;
// Weapons particles spritesheet loaded into an SDL Texture
SDL_Texture* weaponsParticlesTexture = nullptr;
public:
// Template particle for an explosion
Particle explosion;
Particle enemyExplosion;
Particle bullet1;
Particle bullet2;
Particle bullet3;
Particle bullet4;
Particle bullet5;
Particle enemyBullet;
Particle turretMissile;
Particle greenFighterBullet;
Particle sbFirecannon;
Particle sbExplosion;
Particle sbSparks;
Particle sbBombs;
Particle sbBombExplosion;
Particle falconExplosion;
Particle shellExplosion;
Particle bombExplosion;
Particle ceilingExplosion;
};
#endif