From 712744c5c985a906891a41679adbe6468e82649b Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sun, 14 Dec 2008 03:43:37 +0100 Subject: Fixed follow-parent of nested and being-following particle emitters --- src/particle.cpp | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) (limited to 'src/particle.cpp') diff --git a/src/particle.cpp b/src/particle.cpp index fd86195c..adc4aa5b 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -193,7 +193,7 @@ bool Particle::update() p++ ) { - (*p)->moveBy(mPos.x, mPos.y, mPos.z); + (*p)->moveBy(mPos); mChildParticles.push_back (*p); } } @@ -228,6 +228,30 @@ bool Particle::update() } return true; +} + +void Particle::moveBy(Vector change) +{ + mPos += change; + for (ParticleIterator p = mChildParticles.begin(); + p != mChildParticles.end(); + p++) + { + if ((*p)->doesFollow()) + { + (*p)->moveBy(change); + } + } + return; +} + +void Particle::moveTo(float x, float y) +{ + Vector pos; + pos.x = x; + pos.y = y; + pos.z = mPos.z; + moveTo(pos); } Particle* Particle::addEffect(const std::string &particleEffectFile, @@ -275,17 +299,18 @@ Particle* Particle::addEffect(const std::string &particleEffectFile, } // Read and set the basic properties of the particle - int offsetX = XML::getProperty(effectChildNode, "position-x", 0); - int offsetY = XML::getProperty(effectChildNode, "position-y", 0); - int offsetZ = XML::getProperty(effectChildNode, "position-z", 0); - - int particleX = (int) mPos.x + pixelX + offsetX; - int particleY = (int) mPos.y + pixelY + offsetY; - int particleZ = (int) mPos.z + offsetZ; + float offsetX = XML::getFloatProperty(effectChildNode, "position-x", 0); + float offsetY = XML::getFloatProperty(effectChildNode, "position-y", 0); + float offsetZ = XML::getFloatProperty(effectChildNode, "position-z", 0); + + Vector position; + position.x = mPos.x + (float)pixelX + offsetX; + position.y = mPos.y + (float)pixelY + offsetY; + position.z = mPos.z + offsetZ; int lifetime = XML::getProperty(effectChildNode, "lifetime", -1); - newParticle->setPosition(particleX, particleY, particleZ); + newParticle->moveTo(position); newParticle->setLifetime(lifetime); // Look for additional emitters for this particle @@ -311,7 +336,7 @@ Particle *Particle::addTextSplashEffect(const std::string &text, { Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, font); - newParticle->setPosition(x, y, 0); + newParticle->moveTo(x, y); newParticle->setVelocity(((rand() % 100) - 50) / 200.0f, // X ((rand() % 100) - 50) / 200.0f, // Y ((rand() % 100) / 200.0f) + 4.0f); // Z @@ -330,7 +355,7 @@ Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, int x, int y) { Particle *newParticle = new TextParticle(mMap, text, 255, 255, 255, font); - newParticle->setPosition(x, y, 0); + newParticle->moveTo(x, y); newParticle->setVelocity(0.0f, 0.0f, 0.5f); newParticle->setGravity(0.0015f); newParticle->setLifetime(300); -- cgit v1.2.3-70-g09d2