jubilant-funicular
ParticleBatch2D.h
1 #ifndef PARTICLEBATCH2D_H_INCLUDED
2 #define PARTICLEBATCH2D_H_INCLUDED
3 
4 #include <functional>
5 
6 #include "SpriteBatch.h"
7 
8 namespace nta {
10  struct Particle2D {
11  Particle2D(){
12  }
13  Particle2D(crvec2 c, crvec2 v, crvec4 col) : center(c), velocity(v), color(col) {
14  }
15  glm::vec2 center;
16  glm::vec2 velocity;
17  glm::vec4 color;
18  float life;
19  };
22  private:
24  int getFreeParticle() const;
26  std::function<void(Particle2D&, float)> m_updateFunction;
28  Particle2D* m_particles = nullptr;
32  float m_decayRate;
34  float m_radius;
39  public:
45  void init(float il, float dr, float r, int mp, int tex, std::function<void(Particle2D&, float)> updateFunc);
47  void addParticle(Particle2D p);
49  void draw(SpriteBatch& batch) const;
51  void update(float dt);
53  void clear();
54  };
55 };
56 
57 #endif // PARTICLEBATCH2D_H_INCLUDED
nta::ParticleBatch2D
Represents a batch of particles of the same "type".
Definition: ParticleBatch2D.h:21
nta::ParticleBatch2D::m_radius
float m_radius
the radius of an individual particle
Definition: ParticleBatch2D.h:34
nta::ParticleBatch2D::ParticleBatch2D
ParticleBatch2D()
basic constructor
Definition: ParticleBatch2D.cpp:6
nta::ParticleBatch2D::update
void update(float dt)
updates the particles
Definition: ParticleBatch2D.cpp:49
nta::ParticleBatch2D::draw
void draw(SpriteBatch &batch) const
draws all the particles
Definition: ParticleBatch2D.cpp:41
nta::SpriteBatch
Definition: SpriteBatch.h:87
nta::ParticleBatch2D::m_textureID
int m_textureID
texture used by the particles
Definition: ParticleBatch2D.h:38
nta::ParticleBatch2D::getFreeParticle
int getFreeParticle() const
returns index of particle with the minimum life
Definition: ParticleBatch2D.cpp:25
nta::Particle2D
Represents a simple 2d particle.
Definition: ParticleBatch2D.h:10
nta::ParticleBatch2D::clear
void clear()
removes all particles
Definition: ParticleBatch2D.cpp:57
nta
Definition: Animation2D.h:6
nta::ParticleBatch2D::m_maxParticles
int m_maxParticles
maximum number of particles allowed
Definition: ParticleBatch2D.h:36
nta::ParticleBatch2D::m_decayRate
float m_decayRate
the rate with which particles lose life
Definition: ParticleBatch2D.h:32
nta::ParticleBatch2D::addParticle
void addParticle(Particle2D p)
adds a particle to the batch
Definition: ParticleBatch2D.cpp:36
nta::ParticleBatch2D::m_updateFunction
std::function< void(Particle2D &, float)> m_updateFunction
the function used to update the particles
Definition: ParticleBatch2D.h:26
nta::ParticleBatch2D::m_initialLife
float m_initialLife
the life every particle starts out with
Definition: ParticleBatch2D.h:30
nta::ParticleBatch2D::~ParticleBatch2D
~ParticleBatch2D()
deletes particles
Definition: ParticleBatch2D.cpp:8
nta::ParticleBatch2D::m_particles
Particle2D * m_particles
the particles themselves
Definition: ParticleBatch2D.h:28
nta::ParticleBatch2D::init
void init(float il, float dr, float r, int mp, int tex, std::function< void(Particle2D &, float)> updateFunc)
initializes particle batch by specifying properties
Definition: ParticleBatch2D.cpp:13