diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 6 | ||||
-rw-r--r-- | src/particle.cpp | 47 | ||||
-rw-r--r-- | src/particle.h | 17 | ||||
-rw-r--r-- | src/particlecontainer.cpp | 20 | ||||
-rw-r--r-- | src/particlecontainer.h | 6 | ||||
-rw-r--r-- | src/particleemitter.cpp | 11 |
6 files changed, 62 insertions, 45 deletions
diff --git a/src/being.cpp b/src/being.cpp index d98af29c..3f4c5d9c 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -424,8 +424,10 @@ void Being::logic() } } - //Update particle effects - mChildParticleEffects.setPositions((float)mPx + 16.0f, (float)mPy + 32.0f); + // Update particle effects + mChildParticleEffects.moveTo((float) mPx + 16.0f, + (float) mPy + 32.0f); + } void Being::draw(Graphics *graphics, int offsetX, int offsetY) const 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); diff --git a/src/particle.h b/src/particle.h index ab08968f..8359ab55 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 12ef5733..fbfb1505 100644 --- a/src/particlecontainer.cpp +++ b/src/particlecontainer.cpp @@ -44,12 +44,10 @@ ParticleContainer::clear() mNext->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,15 +89,14 @@ 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,16 +153,15 @@ 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 cf002fbc..ae02326e 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 03fe4672..d1ba92ca 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -360,12 +360,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); |