aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/crepe/Particle.cpp21
-rw-r--r--src/crepe/system/ParticleSystem.cpp2
2 files changed, 14 insertions, 9 deletions
diff --git a/src/crepe/Particle.cpp b/src/crepe/Particle.cpp
index d2b1880..cb2ef0d 100644
--- a/src/crepe/Particle.cpp
+++ b/src/crepe/Particle.cpp
@@ -5,25 +5,30 @@
using namespace crepe;
void Particle::reset(uint32_t lifespan, Vector2 position, Vector2 velocity, double angle) {
+ // Initialize the particle state
this->time_in_life = 0;
this->lifespan = lifespan;
this->position = position;
this->velocity = velocity;
- this->active = true;
this->angle = angle;
+ this->active = true;
+ // Reset force accumulation
+ this->force_over_time = {0, 0};
}
void Particle::update() {
- time_in_life++;
- if (time_in_life >= lifespan)
- {
+ // Deactivate particle if it has exceeded its lifespan
+ if (++time_in_life >= lifespan) {
this->active = false;
return;
- }
- velocity += force_over_time;
- position += velocity;
+ }
+
+ // Update velocity based on accumulated force and update position
+ this->velocity += force_over_time;
+ this->position += velocity;
}
void Particle::stop_movement() {
- this->velocity = {0,0};
+ // Reset velocity to halt movement
+ this->velocity = {0, 0};
}
diff --git a/src/crepe/system/ParticleSystem.cpp b/src/crepe/system/ParticleSystem.cpp
index a0b1e55..33027f8 100644
--- a/src/crepe/system/ParticleSystem.cpp
+++ b/src/crepe/system/ParticleSystem.cpp
@@ -38,7 +38,7 @@ void ParticleSystem::update() {
check_bounds(emitter, transform);
}
- update_count = (update_count + 1) % MAX_UPDATE_COUNT;
+ this->update_count = (this->update_count + 1) % this->MAX_UPDATE_COUNT;
}
void ParticleSystem::emit_particle(ParticleEmitter & emitter, const Transform& transform) {