|
|
|
@ -2,7 +2,7 @@
|
|
|
|
|
#include "graphics.h"
|
|
|
|
|
#include <framework/core/clock.h>
|
|
|
|
|
|
|
|
|
|
Particle::Particle(const Rect& rect, float vx, float vy, float ax, float ay, const Color& color, TexturePtr texture)
|
|
|
|
|
Particle::Particle(const Rect& rect, float vx, float vy, float ax, float ay, float duration, const Color& color, TexturePtr texture)
|
|
|
|
|
{
|
|
|
|
|
m_rect = rect;
|
|
|
|
|
m_ix = rect.x(); m_iy = rect.y();
|
|
|
|
@ -10,6 +10,7 @@ Particle::Particle(const Rect& rect, float vx, float vy, float ax, float ay, con
|
|
|
|
|
m_ax = ax; m_ay = ay;
|
|
|
|
|
m_color = color;
|
|
|
|
|
m_texture = texture;
|
|
|
|
|
m_duration = duration;
|
|
|
|
|
m_startTicks = g_clock.ticks();
|
|
|
|
|
m_finished = false;
|
|
|
|
|
}
|
|
|
|
@ -33,11 +34,18 @@ void Particle::update()
|
|
|
|
|
{
|
|
|
|
|
ticks_t t = g_clock.ticks() - m_startTicks;
|
|
|
|
|
|
|
|
|
|
// check if finished
|
|
|
|
|
if(m_duration > 0 && t > m_duration * 1000) {
|
|
|
|
|
m_finished = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//update position
|
|
|
|
|
m_rect.moveTo(m_ix + (m_vx * t / 1000.0) + (m_ax * t*t / 2000.0),
|
|
|
|
|
m_iy + (m_vy * t / 1000.0) + (m_ay * t*t / 2000.0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Emitter::Emitter(const Point& position, int duration, int particlesPerSecond)
|
|
|
|
|
Emitter::Emitter(const Point& position, float duration, int particlesPerSecond)
|
|
|
|
|
{
|
|
|
|
|
m_position = position;
|
|
|
|
|
m_duration = duration;
|
|
|
|
@ -74,10 +82,10 @@ void Emitter::update()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create some particles
|
|
|
|
|
int currentParticles = elapsedTicks / 1000.0 * m_particlesPerSecond;
|
|
|
|
|
int currentParticles = 1 + elapsedTicks / 1000.0 * m_particlesPerSecond;
|
|
|
|
|
for(int i = m_createdParticles; i < currentParticles; ++i) {
|
|
|
|
|
// todo: add random data generation
|
|
|
|
|
m_particles.push_back(Particle(Rect(100, 100, 16, 16), 16, 8, 0, 0));
|
|
|
|
|
m_particles.push_back(Particle(Rect(100, 100, 16, 16), 16, 8, 0, 0, 1.5));
|
|
|
|
|
}
|
|
|
|
|
m_createdParticles = currentParticles;
|
|
|
|
|
}
|
|
|
|
@ -100,7 +108,6 @@ void ParticlesSystem::update()
|
|
|
|
|
it = m_emitters.erase(it);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(*it).update();
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|