diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2008-06-24 12:29:33 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2008-06-24 12:29:33 +0000 |
commit | bea93daec3ad4e3345c701e5dcce250c44d128f2 (patch) | |
tree | b8056f0d9ec3f634cf21c21e86a06094a43eb6fa | |
parent | 5f391618757e93c010141380583ff487848286da (diff) | |
download | mana-client-bea93daec3ad4e3345c701e5dcce250c44d128f2.tar.gz mana-client-bea93daec3ad4e3345c701e5dcce250c44d128f2.tar.bz2 mana-client-bea93daec3ad4e3345c701e5dcce250c44d128f2.tar.xz mana-client-bea93daec3ad4e3345c701e5dcce250c44d128f2.zip |
Added particle property "follow-parent" which makes the particle move when its parent particle is moved.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | src/particle.cpp | 12 | ||||
-rw-r--r-- | src/particle.h | 19 | ||||
-rw-r--r-- | src/particleemitter.cpp | 7 | ||||
-rw-r--r-- | src/particleemitter.h | 1 |
5 files changed, 45 insertions, 0 deletions
@@ -1,5 +1,11 @@ 2008-06-23 Philipp Sehmisch <tmw@crushnet.org> + * 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 <tmw@crushnet.org> + * src/imageparticle.cpp, src/particle.cpp, src/particle.h, src/particleemitter.cpp, src/particleemitter.h, src/textparticle.cpp: Implemented "alpha" particle property. 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. */ @@ -235,6 +239,20 @@ class Particle : public Sprite { 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<float> mParticleGravity; MinMax<int> mParticleRandomnes; MinMax<float> mParticleBounce; + bool mParticleFollow; /* * Properties of targeting particles: |