summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2008-06-23 14:44:20 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2008-06-23 14:44:20 +0000
commit4ec7db55c227d3c38f2358fa74ff2649d6583391 (patch)
tree20f784d7a90b1a22b377ffd0d55fb3251986b5e2 /src
parent6e9aa693c6f07c99e5b84ee35570a14efe4df393 (diff)
downloadmana-4ec7db55c227d3c38f2358fa74ff2649d6583391.tar.gz
mana-4ec7db55c227d3c38f2358fa74ff2649d6583391.tar.bz2
mana-4ec7db55c227d3c38f2358fa74ff2649d6583391.tar.xz
mana-4ec7db55c227d3c38f2358fa74ff2649d6583391.zip
Implemented "alpha" particle property.
Diffstat (limited to 'src')
-rw-r--r--src/imageparticle.cpp2
-rw-r--r--src/particle.cpp1
-rw-r--r--src/particle.h8
-rw-r--r--src/particleemitter.cpp7
-rw-r--r--src/particleemitter.h8
-rw-r--r--src/textparticle.cpp4
6 files changed, 24 insertions, 6 deletions
diff --git a/src/imageparticle.cpp b/src/imageparticle.cpp
index 17581a2a..965434b0 100644
--- a/src/imageparticle.cpp
+++ b/src/imageparticle.cpp
@@ -56,7 +56,7 @@ void ImageParticle::draw(Graphics *graphics, int offsetX, int offsetY) const
return;
}
- float alphafactor = 1.0f;
+ float alphafactor = mAlpha;
if (mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut)
alphafactor *= (float) mLifetimeLeft / (float) mFadeOut;
diff --git a/src/particle.cpp b/src/particle.cpp
index ac40fe1a..fd45430c 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -57,6 +57,7 @@ Particle::Particle(Map *map):
mLifetimePast(0),
mFadeOut(0),
mFadeIn(0),
+ mAlpha(1.0f),
mAutoDelete(true),
mMap(map),
mGravity(0.0f),
diff --git a/src/particle.h b/src/particle.h
index 045ab9b9..5ba2668b 100644
--- a/src/particle.h
+++ b/src/particle.h
@@ -184,6 +184,13 @@ class Particle : public Sprite
{ mFadeIn = fadeIn; }
/**
+ * Sets the alpha value of the particle
+ */
+ void
+ setAlpha(float alpha)
+ { mAlpha = alpha; }
+
+ /**
* Sets the sprite iterator of the particle on the current map to make
* it easier to remove the particle from the map when it is destroyed.
*/
@@ -265,6 +272,7 @@ class Particle : public Sprite
int mLifetimePast; /**< Age of the particle in game ticks*/
int mFadeOut; /**< Lifetime in game ticks left where fading out begins*/
int mFadeIn; /**< Age in game ticks where fading in is finished*/
+ float mAlpha; /**< Opacity of the graphical representation of the particle */
private:
// generic properties
diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp
index 6f66b632..8f46c32b 100644
--- a/src/particleemitter.cpp
+++ b/src/particleemitter.cpp
@@ -61,6 +61,7 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *
mParticleFadeOut.set(0);
mParticleFadeIn.set(0);
mOutput.set(1);
+ mParticleAlpha.set(1.0f);
for_each_xml_child_node(propertyNode, emitterNode)
{
@@ -153,6 +154,10 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *
{
mParticleFadeIn = readMinMax(propertyNode, 0);
}
+ else if (name == "alpha")
+ {
+ mParticleAlpha = readMinMax(propertyNode, 1.0f);
+ }
else
{
logger->log("Particle Engine: Warning, unknown emitter property \"%s\"",
@@ -260,6 +265,7 @@ ParticleEmitter & ParticleEmitter::operator=(const ParticleEmitter &o)
mParticleLifetime = o.mParticleLifetime;
mParticleFadeOut = o.mParticleFadeOut;
mParticleFadeIn = o.mParticleFadeIn;
+ mParticleAlpha = o.mParticleAlpha;
mMap = o.mMap;
mOutput = o.mOutput;
mParticleImage = o.mParticleImage;
@@ -343,6 +349,7 @@ ParticleEmitter::createParticles()
newParticle->setLifetime(mParticleLifetime.value());
newParticle->setFadeOut(mParticleFadeOut.value());
newParticle->setFadeIn(mParticleFadeIn.value());
+ newParticle->setAlpha(mParticleAlpha.value());
for (std::list<ParticleEmitter>::iterator i = mParticleChildEmitters.begin();
i != mParticleChildEmitters.end();
diff --git a/src/particleemitter.h b/src/particleemitter.h
index c9524488..b7331527 100644
--- a/src/particleemitter.h
+++ b/src/particleemitter.h
@@ -119,10 +119,12 @@ class ParticleEmitter
MinMax<int> mOutput; /**< Number of particles spawned per update */
+ /*
+ * Graphical representation of the particle
+ */
Image *mParticleImage; /**< Particle image, if used */
-
- /** Filename of particle animation file */
- Animation mParticleAnimation;
+ Animation mParticleAnimation; /**< Filename of particle animation file */
+ MinMax<float> mParticleAlpha; /**< Opacity of the graphical representation of the particles */
/** List of emitters the spawned particles are equipped with */
std::list<ParticleEmitter> mParticleChildEmitters;
diff --git a/src/textparticle.cpp b/src/textparticle.cpp
index 4bc859cd..89466006 100644
--- a/src/textparticle.cpp
+++ b/src/textparticle.cpp
@@ -45,7 +45,7 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const
int screenX = (int) mPos.x + offsetX;
int screenY = (int) mPos.y - (int) mPos.z + offsetY;
- int alpha = 255;
+ float alpha = mAlpha * 255.0f;
if (mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut)
{
@@ -60,6 +60,6 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const
}
graphics->setFont(mTextFont);
- graphics->setColor(gcn::Color(mColorR, mColorG, mColorB, alpha));
+ graphics->setColor(gcn::Color(mColorR, mColorG, mColorB, (int)alpha));
graphics->drawText(mText, screenX, screenY, gcn::Graphics::CENTER);
}