diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-14 11:47:09 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-14 11:47:09 +0100 |
commit | eab3c5a0de59c3f76272b586b375f7914a88a2ee (patch) | |
tree | 2a9ec306714ddd37d088fc22197160d48105e743 /src/crepe/Particle.cpp | |
parent | a61e3d522c29cfea966a06bb9f9e5e42eae2b7ab (diff) | |
parent | 3d237aed79980e8703ca53df0549e0b48816e464 (diff) |
merge jaro/particle-system-improvement
Diffstat (limited to 'src/crepe/Particle.cpp')
-rw-r--r-- | src/crepe/Particle.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/crepe/Particle.cpp b/src/crepe/Particle.cpp index 485a0d4..b340826 100644 --- a/src/crepe/Particle.cpp +++ b/src/crepe/Particle.cpp @@ -2,8 +2,8 @@ using namespace crepe; -void Particle::reset(uint32_t lifespan, const vec2 & position, const vec2 & velocity, - double angle) { +void Particle::reset(unsigned int lifespan, const vec2 & position, const vec2 & velocity, + float angle) { // Initialize the particle state this->time_in_life = 0; this->lifespan = lifespan; @@ -15,16 +15,17 @@ void Particle::reset(uint32_t lifespan, const vec2 & position, const vec2 & velo this->force_over_time = {0, 0}; } -void Particle::update() { +void Particle::update(double dt) { // Deactivate particle if it has exceeded its lifespan - if (++time_in_life >= lifespan) { + time_in_life += dt; + if (time_in_life >= lifespan) { this->active = false; return; } // Update velocity based on accumulated force and update position - this->velocity += force_over_time; - this->position += velocity; + this->velocity += force_over_time * dt; + this->position += velocity * dt; } void Particle::stop_movement() { |