From 864e33db117a28256a89d03e750b38df044bee6e 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 e534527f..2f274a5c 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -194,7 +194,7 @@ bool Particle::update() p++ ) { - (*p)->moveBy(mPos.x, mPos.y, mPos.z); + (*p)->moveBy(mPos); mChildParticles.push_back (*p); } } @@ -229,6 +229,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, @@ -276,17 +300,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 @@ -312,7 +337,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 @@ -331,7 +356,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