summaryrefslogtreecommitdiff
path: root/src/particle.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/particle.h')
-rw-r--r--src/particle.h84
1 files changed, 33 insertions, 51 deletions
diff --git a/src/particle.h b/src/particle.h
index 69f8c2be..0e39883b 100644
--- a/src/particle.h
+++ b/src/particle.h
@@ -22,8 +22,8 @@
#ifndef PARTICLE_H
#define PARTICLE_H
+#include "actor.h"
#include "guichanfwd.h"
-#include "sprite.h"
#include "vector.h"
#include <list>
@@ -41,9 +41,19 @@ typedef Emitters::iterator EmitterIterator;
/**
* A particle spawned by a ParticleEmitter.
*/
-class Particle : public Sprite
+class Particle : public Actor
{
public:
+ enum AliveStatus
+ {
+ ALIVE = 0,
+ DEAD_TIMEOUT = 1,
+ DEAD_FLOOR = 2,
+ DEAD_SKY = 4,
+ DEAD_IMPACT = 8,
+ DEAD_OTHER = 16,
+ DEAD_LONG_AGO = 128
+ };
static const float PARTICLE_SKY; /**< Maximum Z position of particles */
static int fastPhysics; /**< Mode of squareroot calculation */
static int particleCount; /**< Current number of particles */
@@ -83,7 +93,7 @@ class Particle : public Sprite
/**
* Draws the particle image.
*/
- virtual void draw(Graphics *graphics, int offsetX, int offsetY) const;
+ virtual bool draw(Graphics *graphics, int offsetX, int offsetY) const;
/**
* Necessary for sorting with the other sprites.
@@ -92,12 +102,6 @@ class Particle : public Sprite
{ return (int) (mPos.y + mPos.z) - 64; }
/**
- * Sets the map the particle is on.
- */
- void setMap(Map *map);
-
-
- /**
* Creates a blank particle as a child of the current particle
* Useful for creating target particles
*/
@@ -142,12 +146,6 @@ class Particle : public Sprite
void moveTo(float x, float y);
/**
- * Returns the particle position.
- */
- const Vector& getPosition() const
- { return mPos; }
-
- /**
* Changes the particle position relative
*/
void moveBy (const Vector &change);
@@ -173,32 +171,6 @@ class Particle : public Sprite
{ mFadeIn = fadeIn; }
/**
- * Sets the alpha value of the particle
- */
- void setAlpha(float alpha)
- { mAlpha = alpha; }
-
- /**
- * Returns the current alpha opacity of the particle.
- */
- virtual float getAlpha() const
- { return mAlpha; }
-
- /**
- * 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.
- */
- void setSpriteIterator(std::list<Sprite*>::iterator spriteIterator)
- { mSpriteIterator = spriteIterator; }
-
- /**
- * Gets the sprite iterator of the particle on the current map.
- */
- std::list<Sprite*>::iterator
- getSpriteIterator() const
- { return mSpriteIterator; }
-
- /**
* Sets the current velocity in 3 dimensional space.
*/
void setVelocity(float x, float y, float z)
@@ -259,20 +231,20 @@ class Particle : public Sprite
void setAllowSizeAdjust(bool adjust)
{ mAllowSizeAdjust = adjust; }
- bool isAlive()
- { return mAlive; }
+ bool isAlive() const
+ { return mAlive == ALIVE; }
/**
* Determines whether the particle and its children are all dead
*/
- bool isExtinct()
+ bool isExtinct() const
{ return !isAlive() && mChildParticles.empty(); }
/**
* Manually marks the particle for deletion.
*/
void kill()
- { mAlive = false; mAutoDelete = true; }
+ { mAlive = DEAD_OTHER; mAutoDelete = true; }
/**
* After calling this function the particle will only request
@@ -285,28 +257,38 @@ class Particle : public Sprite
virtual int getNumberOfLayers() const
{ return 1; }
+ virtual float getAlpha() const
+ { return 1.0f; }
+
+ virtual void setAlpha(float alpha) {}
+
+ virtual void setDeathEffect(const std::string &effectFile, char conditions)
+ { mDeathEffect = effectFile; mDeathEffectConditions = conditions; }
+
protected:
+ /** Opacity of the graphical representation of the particle */
+ float mAlpha;
+
/** Calculates the current alpha transparency taking current fade status into account*/
float getCurrentAlpha() const;
- bool mAlive; /**< Is the particle supposed to be drawn and updated?*/
- Vector mPos; /**< Position in pixels relative to map. */
int mLifetimeLeft; /**< Lifetime left in game ticks*/
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 */
+ Vector mVelocity; /**< Speed in pixels per game-tick. */
+ private:
+ AliveStatus mAlive; /**< Is the particle supposed to be drawn and updated?*/
// generic properties
bool mAutoDelete; /**< May the particle request its deletion by the parent particle? */
- Map *mMap; /**< Map the particle is on. */
- std::list<Sprite*>::iterator mSpriteIterator; /**< iterator of the particle on the current map */
Emitters mChildEmitters; /**< List of child emitters. */
Particles mChildParticles; /**< List of particles controlled by this particle */
bool mAllowSizeAdjust; /**< Can the effect size be adjusted by the object props in the map file? */
+ std::string mDeathEffect; /**< Particle effect file to be spawned when the particle dies */
+ char mDeathEffectConditions;/**< Bitfield of death conditions which trigger spawning of the death particle */
// dynamic particle
- Vector mVelocity; /**< Speed in pixels per game-tick. */
float mGravity; /**< Downward acceleration in pixels per game-tick. */
int mRandomness; /**< Ammount of random vector change */
float mBounce; /**< How much the particle bounces off when hitting the ground */