diff options
author | Philipp Sehmisch <crush@themanaworld.org> | 2008-12-14 03:43:37 +0100 |
---|---|---|
committer | Philipp Sehmisch <crush@themanaworld.org> | 2008-12-14 03:43:37 +0100 |
commit | 864e33db117a28256a89d03e750b38df044bee6e (patch) | |
tree | 709e71008e734ce18400721e9779da3f71f70cce /src | |
parent | 59f441730d8dbd7574b2fe4c9a430be256449cab (diff) | |
download | mana-client-864e33db117a28256a89d03e750b38df044bee6e.tar.gz mana-client-864e33db117a28256a89d03e750b38df044bee6e.tar.bz2 mana-client-864e33db117a28256a89d03e750b38df044bee6e.tar.xz mana-client-864e33db117a28256a89d03e750b38df044bee6e.zip |
Fixed follow-parent of nested and being-following particle emitters
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 4 | ||||
-rw-r--r-- | src/particle.cpp | 47 | ||||
-rw-r--r-- | src/particle.h | 17 | ||||
-rw-r--r-- | src/particlecontainer.cpp | 16 | ||||
-rw-r--r-- | src/particlecontainer.h | 6 | ||||
-rw-r--r-- | src/particleemitter.cpp | 11 |
6 files changed, 60 insertions, 41 deletions
diff --git a/src/being.cpp b/src/being.cpp index 7641de35..88063ac1 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -403,8 +403,8 @@ void Being::logic() } // Update particle effects - mChildParticleEffects.setPositions((float) mPx + 16.0f, - (float) mPy + 32.0f); + mChildParticleEffects.moveTo((float) mPx + 16.0f, + (float) mPy + 32.0f); } 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); diff --git a/src/particle.h b/src/particle.h index 2077af43..d0585192 100644 --- a/src/particle.h +++ b/src/particle.h @@ -127,14 +127,13 @@ class Particle : public Sprite /** * Sets the position in 3 dimensional space in pixels relative to map. */ - void setPosition(float x, float y, float z) - { mPos.x = x; mPos.y = y; mPos.z = z; } + void moveTo(Vector pos) + { moveBy (pos - mPos);} /** * Sets the position in 2 dimensional space in pixels relative to map. */ - void setPosition(float x, float y) - { mPos.x = x; mPos.y = y; } + void moveTo(float x, float y); /** * Returns the particle position. @@ -144,14 +143,8 @@ class Particle : public Sprite /** * Changes the particle position relative - */ - void moveBy(float x, float y, float z) - { mPos.x += x; mPos.y += y; mPos.z += z; } - - void moveChildren(Vector change); - - void moveBy (Vector change) - { mPos += change; } + */
+ void moveBy (Vector change); /** * Sets the time in game ticks until the particle is destroyed. diff --git a/src/particlecontainer.cpp b/src/particlecontainer.cpp index bf15f1b5..27ba5ede 100644 --- a/src/particlecontainer.cpp +++ b/src/particlecontainer.cpp @@ -45,10 +45,10 @@ void ParticleContainer::clear() } -void ParticleContainer::setPositions(float x, float y) +void ParticleContainer::moveTo(float x, float y) { if (mNext) - mNext->setPositions(x, y); + mNext->moveTo(x, y); } // -- particle list ---------------------------------------- @@ -91,14 +91,14 @@ void ParticleList::clearLocally() mElements.clear(); } -void ParticleList::setPositions(float x, float y) +void ParticleList::moveTo(float x, float y) { - ParticleContainer::setPositions(x, y); + ParticleContainer::moveTo(x, y); for (std::list<Particle *>::iterator it = mElements.begin(); it != mElements.end();) { - (*it)->setPosition(x, y); + (*it)->moveTo(x, y); if ((*it)->isExtinct()) { (*it)->kill(); @@ -156,15 +156,15 @@ void ParticleVector::clearLocally() delLocally(i); } -void ParticleVector::setPositions(float x, float y) +void ParticleVector::moveTo(float x, float y) { - ParticleContainer::setPositions(x, y); + ParticleContainer::moveTo(x, y); for (std::vector<Particle *>::iterator it = mIndexedElements.begin(); it != mIndexedElements.end(); it++) { if (*it) { - (*it)->setPosition(x, y); + (*it)->moveTo(x, y); if ((*it)->isExtinct()) { diff --git a/src/particlecontainer.h b/src/particlecontainer.h index b2bb4399..9d90562b 100644 --- a/src/particlecontainer.h +++ b/src/particlecontainer.h @@ -58,7 +58,7 @@ public: /** * Sets the positions of all elements */ - virtual void setPositions(float x, float y); + virtual void moveTo(float x, float y); protected: bool mDelParent; /**< Delete mNext in destructor */ @@ -88,7 +88,7 @@ public: virtual void clearLocally(); - virtual void setPositions(float x, float y); + virtual void moveTo(float x, float y); protected: std::list<Particle *> mElements; /**< Contained particle effects */ @@ -116,7 +116,7 @@ public: virtual void delLocally(int index); virtual void clearLocally(); - virtual void setPositions(float x, float y); + virtual void moveTo(float x, float y); protected: std::vector<Particle *> mIndexedElements; diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index 5ae1aae5..4cc5ae5a 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -359,12 +359,13 @@ ParticleEmitter::createParticles(int tick) { newParticle = new Particle(mMap); } +
+ Vector position;
+ position.x = mParticlePosX.value(tick);
+ position.y = mParticlePosY.value(tick);
+ position.z = mParticlePosZ.value(tick); - - newParticle->setPosition( - mParticlePosX.value(tick), - mParticlePosY.value(tick), - mParticlePosZ.value(tick)); + newParticle->moveTo(position); float angleH = mParticleAngleHorizontal.value(tick); float angleV = mParticleAngleVertical.value(tick); |