aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/Particle.cpp
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-11 19:48:18 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-11 19:48:18 +0100
commit141c4831be82654a692d03fdb0fbf87fa27dea88 (patch)
tree02bc3294cf44e3f962595d05bbdfcc0484d0d9f3 /src/crepe/Particle.cpp
parentca878336da5cdd120a929e6ce84f565ce5365248 (diff)
parente42d0877592aa1e88afbe0bc65822cd53a82205d (diff)
Merge branch 'jaro/particle-system-master' into niels/RenderingParticle
Diffstat (limited to 'src/crepe/Particle.cpp')
-rw-r--r--src/crepe/Particle.cpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/crepe/Particle.cpp b/src/crepe/Particle.cpp
index 4810e80..ab55f37 100644
--- a/src/crepe/Particle.cpp
+++ b/src/crepe/Particle.cpp
@@ -2,19 +2,32 @@
using namespace crepe;
-Particle::Particle() { this->active = false; }
-
-void Particle::reset(float lifespan, Position position, Position velocity) {
+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->angle = angle;
this->active = true;
+ // Reset force accumulation
+ this->force_over_time = {0, 0};
+}
+
+void Particle::update() {
+ // Deactivate particle if it has exceeded its lifespan
+ 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;
}
-void Particle::update(float deltaTime) {
- time_in_life += deltaTime;
- position.x += velocity.x * deltaTime;
- position.y += velocity.y * deltaTime;
- if (time_in_life >= lifespan) this->active = false;
+void Particle::stop_movement() {
+ // Reset velocity to halt movement
+ this->velocity = {0, 0};
}