aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/Particle.cpp
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-11-10 18:14:57 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-11-10 18:14:57 +0100
commit08d48aabac838a641ef918da92d9827b214e5da6 (patch)
tree1501556f2e0fbeb7ac67694b4a547a76708dfb4c /src/crepe/Particle.cpp
parent760351abd1a6609a8fe0de1269ac69ea275f4250 (diff)
added comments and code standard
Diffstat (limited to 'src/crepe/Particle.cpp')
-rw-r--r--src/crepe/Particle.cpp21
1 files changed, 13 insertions, 8 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};
}