summaryrefslogtreecommitdiff
path: root/src/particle.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2008-12-14 03:43:37 +0100
committerIra Rice <irarice@gmail.com>2008-12-14 09:13:39 -0700
commit712744c5c985a906891a41679adbe6468e82649b (patch)
treec6f49cd89cf84e00212ba655629465a6c8cf106b /src/particle.cpp
parentae7cd9ca453aee25ccf1f4eb277ab77144910da5 (diff)
downloadmana-712744c5c985a906891a41679adbe6468e82649b.tar.gz
mana-712744c5c985a906891a41679adbe6468e82649b.tar.bz2
mana-712744c5c985a906891a41679adbe6468e82649b.tar.xz
mana-712744c5c985a906891a41679adbe6468e82649b.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 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);