diff options
Diffstat (limited to 'src/crepe')
-rw-r--r-- | src/crepe/Particle.h | 3 | ||||
-rw-r--r-- | src/crepe/api/ParticleEmitter.cpp | 6 | ||||
-rw-r--r-- | src/crepe/api/ParticleEmitter.h | 5 | ||||
-rw-r--r-- | src/crepe/system/ParticleSystem.cpp | 10 | ||||
-rw-r--r-- | src/crepe/system/ParticleSystem.h | 1 |
5 files changed, 15 insertions, 10 deletions
diff --git a/src/crepe/Particle.h b/src/crepe/Particle.h index 0170117..ee0cd66 100644 --- a/src/crepe/Particle.h +++ b/src/crepe/Particle.h @@ -41,7 +41,8 @@ public: * \param velocity The initial velocity of the particle. * \param angle The angle of the particle's trajectory or orientation. */ - void reset(unsigned int lifespan, const vec2 & position, const vec2 & velocity, float angle); + void reset(unsigned int lifespan, const vec2 & position, const vec2 & velocity, + float angle); /** * \brief Updates the particle's state. * diff --git a/src/crepe/api/ParticleEmitter.cpp b/src/crepe/api/ParticleEmitter.cpp index 1e9cfaa..4f54bbd 100644 --- a/src/crepe/api/ParticleEmitter.cpp +++ b/src/crepe/api/ParticleEmitter.cpp @@ -3,9 +3,11 @@ using namespace crepe; -ParticleEmitter::ParticleEmitter(game_object_id_t game_object_id, const Sprite & sprite, const Data & data) +ParticleEmitter::ParticleEmitter(game_object_id_t game_object_id, const Sprite & sprite, + const Data & data) : Component(game_object_id), - sprite(sprite), data(data) { + sprite(sprite), + data(data) { for (size_t i = 0; i < this->data.max_particles; i++) { this->particles.emplace_back(); } diff --git a/src/crepe/api/ParticleEmitter.h b/src/crepe/api/ParticleEmitter.h index 5b8e8e3..be970f5 100644 --- a/src/crepe/api/ParticleEmitter.h +++ b/src/crepe/api/ParticleEmitter.h @@ -78,18 +78,19 @@ public: * \param game_object_id Identifier for the game object using this emitter. * \param data Configuration data defining particle properties. */ - ParticleEmitter(game_object_id_t game_object_id, const Sprite & sprite,const Data & data); + ParticleEmitter(game_object_id_t game_object_id, const Sprite & sprite, const Data & data); public: //! Configuration data for particle emission settings. Data data; + private: //! Only ParticleSystem can move and read particles friend ParticleSystem; //! Only RenderSystem can read particles friend RenderSystem; //! Saves time left over from last update event. - float spawn_accumulator = 0; + float spawn_accumulator = 0; //! collection of particles std::vector<Particle> particles; }; diff --git a/src/crepe/system/ParticleSystem.cpp b/src/crepe/system/ParticleSystem.cpp index f98f245..31a4e9e 100644 --- a/src/crepe/system/ParticleSystem.cpp +++ b/src/crepe/system/ParticleSystem.cpp @@ -31,8 +31,8 @@ void ParticleSystem::update() { while (emitter.spawn_accumulator >= 1.0) { this->emit_particle(emitter, transform); emitter.spawn_accumulator -= 1.0; - } - + } + // Update all particles for (Particle & particle : emitter.particles) { if (particle.active) { @@ -49,9 +49,11 @@ void ParticleSystem::emit_particle(ParticleEmitter & emitter, const Transform & constexpr float DEG_TO_RAD = M_PI / 180.0; vec2 initial_position = emitter.data.position + transform.position; - float random_angle = this->generate_random_angle(emitter.data.min_angle, emitter.data.max_angle); + float random_angle + = this->generate_random_angle(emitter.data.min_angle, emitter.data.max_angle); - float random_speed = this->generate_random_speed(emitter.data.min_speed, emitter.data.max_speed); + float random_speed + = this->generate_random_speed(emitter.data.min_speed, emitter.data.max_speed); float angle_radians = random_angle * DEG_TO_RAD; vec2 velocity diff --git a/src/crepe/system/ParticleSystem.h b/src/crepe/system/ParticleSystem.h index 95a2bd5..154521d 100644 --- a/src/crepe/system/ParticleSystem.h +++ b/src/crepe/system/ParticleSystem.h @@ -23,7 +23,6 @@ public: void update() override; private: - /** * \brief Emits a particle from the specified emitter based on its emission properties. * |