summaryrefslogtreecommitdiff
path: root/src/particle.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2008-12-14 03:43:37 +0100
committerPhilipp Sehmisch <crush@themanaworld.org>2008-12-14 03:43:37 +0100
commit864e33db117a28256a89d03e750b38df044bee6e (patch)
tree709e71008e734ce18400721e9779da3f71f70cce /src/particle.cpp
parent59f441730d8dbd7574b2fe4c9a430be256449cab (diff)
downloadmana-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/particle.cpp')
-rw-r--r--src/particle.cpp47
1 files changed, 36 insertions, 11 deletions
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);