From bea93daec3ad4e3345c701e5dcce250c44d128f2 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Tue, 24 Jun 2008 12:29:33 +0000 Subject: Added particle property "follow-parent" which makes the particle move when its parent particle is moved. --- ChangeLog | 6 ++++++ src/particle.cpp | 12 ++++++++++++ src/particle.h | 19 +++++++++++++++++++ src/particleemitter.cpp | 7 +++++++ src/particleemitter.h | 1 + 5 files changed, 45 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1e6f8f94..94cbecd5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-06-23 Philipp Sehmisch + + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Added particle property "follow-parent" which + makes the particle move when its parent particle is moved. + 2008-06-23 Philipp Sehmisch * src/imageparticle.cpp, src/particle.cpp, src/particle.h, diff --git a/src/particle.cpp b/src/particle.cpp index fd45430c..3b3f5116 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -63,6 +63,7 @@ Particle::Particle(Map *map): mGravity(0.0f), mRandomnes(0), mBounce(0.0f), + mFollow(false), mTarget(NULL), mAcceleration(0.0f), mInvDieDistance(-1.0f), @@ -95,6 +96,8 @@ Particle::update() mAlive = false; } + Vector oldPos = mPos; + if (mAlive) { //calculate particle movement @@ -191,10 +194,19 @@ Particle::update() } } + Vector change = mPos - oldPos; + // Update child particles + for (ParticleIterator p = mChildParticles.begin(); p != mChildParticles.end();) { + //move particle with its parent if desired + if ((*p)->doesFollow()) + { + (*p)->moveBy(change); + } + //update particle if ((*p)->update()) { p++; diff --git a/src/particle.h b/src/particle.h index 5ba2668b..88a38417 100644 --- a/src/particle.h +++ b/src/particle.h @@ -160,6 +160,10 @@ class Particle : public Sprite moveBy(float x, float y, float z) { mPos.x += x; mPos.y += y; mPos.z += z; } + void + moveBy (Vector change) + { mPos += change; } + /** * Sets the time in game ticks until the particle is destroyed. */ @@ -234,6 +238,20 @@ class Particle : public Sprite setBounce(float bouncieness) { mBounce = bouncieness; } + /** + * Sets the flag if the particle is supposed to be moved by its parent + */ + void + setFollow(bool follow) + { mFollow = follow; } + + /** + * Gets the flag if the particle is supposed to be moved by its parent + */ + bool + doesFollow() + { return mFollow; } + /** * Makes the particle move toward another particle with a * given acceleration and momentum @@ -287,6 +305,7 @@ class Particle : public Sprite float mGravity; /**< Downward acceleration in pixels per game-tick. */ int mRandomnes; /**< Ammount of random vector change */ float mBounce; /**< How much the particle bounces off when hitting the ground */ + bool mFollow; /**< is this particle moved when its parent particle moves? */ // follow-point particles Particle *mTarget; /**< The particle that attracts this particle*/ diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index 8f46c32b..631ca228 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -54,6 +54,7 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map * mParticleGravity.set(0.0f); mParticleRandomnes.set(0); mParticleBounce.set(0.0f); + mParticleFollow = false; mParticleAcceleration.set(0.0f); mParticleDieDistance.set(-1.0f); mParticleMomentum.set(1.0f); @@ -158,6 +159,10 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map * { mParticleAlpha = readMinMax(propertyNode, 1.0f); } + else if (name == "follow-parent") + { + mParticleFollow = true; + } else { logger->log("Particle Engine: Warning, unknown emitter property \"%s\"", @@ -258,6 +263,7 @@ ParticleEmitter & ParticleEmitter::operator=(const ParticleEmitter &o) mParticleGravity = o.mParticleGravity; mParticleRandomnes = o.mParticleRandomnes; mParticleBounce = o.mParticleBounce; + mParticleFollow = o.mParticleFollow; mParticleTarget = o.mParticleTarget; mParticleAcceleration = o.mParticleAcceleration; mParticleDieDistance = o.mParticleDieDistance; @@ -339,6 +345,7 @@ ParticleEmitter::createParticles() newParticle->setRandomnes(mParticleRandomnes.value()); newParticle->setGravity(mParticleGravity.value()); newParticle->setBounce(mParticleBounce.value()); + newParticle->setFollow(mParticleFollow); newParticle->setDestination(mParticleTarget, mParticleAcceleration.value(), diff --git a/src/particleemitter.h b/src/particleemitter.h index b7331527..2f45608d 100644 --- a/src/particleemitter.h +++ b/src/particleemitter.h @@ -99,6 +99,7 @@ class ParticleEmitter MinMax mParticleGravity; MinMax mParticleRandomnes; MinMax mParticleBounce; + bool mParticleFollow; /* * Properties of targeting particles: -- cgit v1.2.3-70-g09d2