-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticleSystem.h
More file actions
94 lines (72 loc) · 1.7 KB
/
ParticleSystem.h
File metadata and controls
94 lines (72 loc) · 1.7 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
/*
* ParticleSystem.h
*
* Created on: 27/06/2020
* Author: vinicius
*/
#ifndef PARTICLESYSTEM_H_
#define PARTICLESYSTEM_H_
#include "Random.h"
#include "Particle.h"
#include <SFML/Graphics.hpp>
#include <vector>
struct SpawnAreaSpecs
{
sf::Vector2f position;
sf::Vector2f size;
};
struct ParticleSystemSpecs
{
int fps;
unsigned int amount;
sf::Vector2f particleSize;
sf::Color color;
float lifetime;
sf::Vector2f gravity;
sf::Vector2f speed;
float gravityEffect;
bool visible = true;
};
class ParticleSystem : public sf::Drawable
{
private:
// Spawn Area
sf::Vector2f m_pos;
sf::Vector2f m_size;
// Particle System specs
std::vector<Particle> m_particles;
int m_fps;
unsigned int m_amount;
sf::Vector2f m_particleSize;
sf::Color m_color;
float m_lifetime;
sf::Vector2f m_gravity;
sf::Vector2f m_speed;
float m_gravityEffect;
bool m_visible;
float m_gap;
unsigned int m_currentParticle = 0;
unsigned int m_frame = 0;
private:
float m_frame2sec(const int& frame) const;
unsigned int m_sec2frame(const float& sec) const;
public:
// Constructor and destructor
ParticleSystem(const SpawnAreaSpecs& saSpecs, const ParticleSystemSpecs& psSpecs);
virtual ~ParticleSystem();
// Functions
void restart();
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
void updatePhysics(const float& delta);
void setPosition(const sf::Vector2i& pos);
void setPosition(const sf::Vector2f& pos);
sf::Vector2f getPosition() const;
void setColor(const sf::Color& color);
sf::Color getColor() const;
void setGravity(const sf::Vector2f& gravity);
sf::Vector2f getGravity() const;
void hide();
void show();
void updateVariables();
};
#endif /* PARTICLESYSTEM_H_ */