summaryrefslogtreecommitdiff
path: root/src/particle.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <mana@crushnet.org>2010-10-17 17:15:21 +0200
committerPhilipp Sehmisch <mana@crushnet.org>2010-10-17 17:15:21 +0200
commit1b21442b5eb6dcc41a585715d07c73ed3ad59a1b (patch)
treec84f226695e1d7bb7d95fcba7c9e8c30333508da /src/particle.cpp
parent1f3c056323de16cbe5965e1d65a69eeab73396ce (diff)
downloadmana-1b21442b5eb6dcc41a585715d07c73ed3ad59a1b.tar.gz
mana-1b21442b5eb6dcc41a585715d07c73ed3ad59a1b.tar.bz2
mana-1b21442b5eb6dcc41a585715d07c73ed3ad59a1b.tar.xz
mana-1b21442b5eb6dcc41a585715d07c73ed3ad59a1b.zip
Added death effects to particle engine.
Every particle can now have a death effect. This is an effect which is created when the particle dies. Which death reasons (timeout, touching floor, touching sky, reaching target or deleted by external call) trigger the effect can also be specified. This is useful for exploding projectiles and many other effects. Reviewed-by: Bertram
Diffstat (limited to 'src/particle.cpp')
-rw-r--r--src/particle.cpp74
1 files changed, 58 insertions, 16 deletions
diff --git a/src/particle.cpp b/src/particle.cpp
index e3c45a9f..cb2faa77 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -56,14 +56,15 @@ bool Particle::enabled = true;
const float Particle::PARTICLE_SKY = 800.0f;
Particle::Particle(Map *map):
- mAlive(true),
+ mAlpha(1.0f),
mLifetimeLeft(-1),
mLifetimePast(0),
mFadeOut(0),
mFadeIn(0),
- mAlpha(1.0f),
+ mAlive(ALIVE),
mAutoDelete(true),
mAllowSizeAdjust(false),
+ mDeathEffectConditions(0x00),
mGravity(0.0f),
mRandomness(0),
mBounce(0.0f),
@@ -81,6 +82,7 @@ Particle::~Particle()
{
// Delete child emitters and child particles
clear();
+ //update particle count
Particle::particleCount--;
}
@@ -104,12 +106,12 @@ bool Particle::update()
if (!mMap)
return false;
- if (mLifetimeLeft == 0)
- mAlive = false;
+ if (mLifetimeLeft == 0 && mAlive == ALIVE)
+ mAlive = DEAD_TIMEOUT;
Vector oldPos = mPos;
- if (mAlive)
+ if (mAlive == ALIVE)
{
//calculate particle movement
if (mMomentum != 1.0f)
@@ -143,7 +145,7 @@ bool Particle::update()
{
if (mInvDieDistance > 0.0f && invHypotenuse > mInvDieDistance)
{
- mAlive = false;
+ mAlive = DEAD_IMPACT;
}
float accFactor = invHypotenuse * mAcceleration;
mVelocity -= dist * accFactor;
@@ -171,7 +173,7 @@ bool Particle::update()
}
mLifetimePast++;
- if (mPos.z > PARTICLE_SKY || mPos.z < 0.0f)
+ if (mPos.z < 0.0f)
{
if (mBounce > 0.0f)
{
@@ -181,8 +183,11 @@ bool Particle::update()
}
else
{
- mAlive = false;
+ mAlive = DEAD_FLOOR;
}
+ } else if (mPos.z > PARTICLE_SKY)
+ {
+ mAlive = DEAD_SKY;
}
// Update child emitters
@@ -202,6 +207,17 @@ bool Particle::update()
}
}
+ // create death effect when the particle died
+ if (mAlive != ALIVE && mAlive != DEAD_LONG_AGO)
+ {
+ if ((mAlive & mDeathEffectConditions) > 0x00 && !mDeathEffect.empty())
+ {
+ Particle* deathEffect = particleEngine->addEffect(mDeathEffect, 0, 0);
+ deathEffect->moveBy(mPos);
+ }
+ mAlive = DEAD_LONG_AGO;
+ }
+
Vector change = mPos - oldPos;
// Update child particles
@@ -225,7 +241,7 @@ bool Particle::update()
p = mChildParticles.erase(p);
}
}
- if (!mAlive && mChildParticles.empty() && mAutoDelete)
+ if (mAlive != ALIVE && mChildParticles.empty() && mAutoDelete)
{
return false;
}
@@ -325,13 +341,39 @@ Particle *Particle::addEffect(const std::string &particleEffectFile,
// Look for additional emitters for this particle
for_each_xml_child_node(emitterNode, effectChildNode)
{
- if (!xmlStrEqual(emitterNode->name, BAD_CAST "emitter"))
- continue;
-
- ParticleEmitter *newEmitter;
- newEmitter = new ParticleEmitter(emitterNode, newParticle, mMap,
- rotation);
- newParticle->addEmitter(newEmitter);
+ if (xmlStrEqual(emitterNode->name, BAD_CAST "emitter"))
+ {
+ ParticleEmitter *newEmitter;
+ newEmitter = new ParticleEmitter(emitterNode, newParticle, mMap,
+ rotation);
+ newParticle->addEmitter(newEmitter);
+ }
+ else if (xmlStrEqual(emitterNode->name, BAD_CAST "deatheffect"))
+ {
+ std::string deathEffect = (const char*)emitterNode->xmlChildrenNode->content;
+ char deathEffectConditions = 0x00;
+ if (XML::getBoolProperty(emitterNode, "on-floor", true))
+ {
+ deathEffectConditions += Particle::DEAD_FLOOR;
+ }
+ if (XML::getBoolProperty(emitterNode, "on-sky", true))
+ {
+ deathEffectConditions += Particle::DEAD_SKY;
+ }
+ if (XML::getBoolProperty(emitterNode, "on-other", false))
+ {
+ deathEffectConditions += Particle::DEAD_OTHER;
+ }
+ if (XML::getBoolProperty(emitterNode, "on-impact", true))
+ {
+ deathEffectConditions += Particle::DEAD_IMPACT;
+ }
+ if (XML::getBoolProperty(emitterNode, "on-timeout", true))
+ {
+ deathEffectConditions += Particle::DEAD_TIMEOUT;
+ }
+ newParticle->setDeathEffect(deathEffect, deathEffectConditions);
+ }
}
mChildParticles.push_back(newParticle);