Mana
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
Particle Class Reference

A particle spawned by a ParticleEmitter. More...

#include <particle.h>

Inheritance diagram for Particle:
Actor ImageParticle TextParticle AnimationParticle RotationalParticle

Public Types

enum  AliveStatus {
  ALIVE = 0 , DEAD_TIMEOUT = 1 , DEAD_FLOOR = 2 , DEAD_SKY = 4 ,
  DEAD_IMPACT = 8 , DEAD_OTHER = 16 , DEAD_LONG_AGO = 128
}
 

Public Member Functions

 Particle (Map *map)
 Constructor.
 
 ~Particle () override
 
void clear ()
 Deletes all child particles and emitters.
 
virtual bool update ()
 Updates particle position, returns false when the particle should be deleted.
 
bool draw (Graphics *graphics, int offsetX, int offsetY) const override
 Draws the particle image.
 
bool drawnWhenBehind () const override
 Do not draw particles when behind other objects.
 
ParticlecreateChild ()
 Creates a blank particle as a child of the current particle Useful for creating target particles.
 
ParticleaddEffect (const std::string &particleEffectFile, int pixelX, int pixelY, int rotation=0)
 Creates a child particle that hosts some emitters described in the particleEffectFile.
 
ParticleaddTextSplashEffect (const std::string &text, int x, int y, const gcn::Color *color, gcn::Font *font, bool outline=false)
 Creates a standalone text particle.
 
ParticleaddTextRiseFadeOutEffect (const std::string &text, int x, int y, const gcn::Color *color, gcn::Font *font, bool outline=false)
 Creates a standalone text particle.
 
void addEmitter (ParticleEmitter *emitter)
 Adds an emitter to the particle.
 
void moveTo (const Vector &pos)
 Sets the position in 3 dimensional space in pixels relative to map.
 
void moveTo (float x, float y)
 Sets the position in 2 dimensional space in pixels relative to map.
 
void moveBy (const Vector &change)
 Changes the particle position relative.
 
void setLifetime (int lifetime)
 Sets the time in game ticks until the particle is destroyed.
 
void setFadeOut (int fadeOut)
 Sets the age of the pixel in game ticks where the particle has faded in completely.
 
void setFadeIn (int fadeIn)
 Sets the remaining particle lifetime where the particle starts to fade out.
 
void setVelocity (float x, float y, float z)
 Sets the current velocity in 3 dimensional space.
 
void setGravity (float gravity)
 Sets the downward acceleration.
 
void setRandomness (int r)
 Sets the ammount of random vector changes.
 
void setBounce (float bouncieness)
 Sets the ammount of velocity particles retain after hitting the ground.
 
void setFollow (bool follow)
 Sets the flag if the particle is supposed to be moved by its parent.
 
bool doesFollow () const
 Gets the flag if the particle is supposed to be moved by its parent.
 
void setDestination (Particle *target, float accel, float moment)
 Makes the particle move toward another particle with a given acceleration and momentum.
 
void setDieDistance (float dist)
 Sets the distance in pixel the particle can come near the target particle before it is destroyed.
 
void adjustEmitterSize (int w, int h)
 Changes the size of the emitters so that the effect fills a rectangle of this size.
 
void setAllowSizeAdjust (bool adjust)
 
bool isAlive () const
 
bool isExtinct () const
 Determines whether the particle and its children are all dead.
 
void kill ()
 Manually marks the particle for deletion.
 
void disableAutoDelete ()
 After calling this function the particle will only request deletion when kill() is called.
 
float getAlpha () const override
 Returns the current alpha value used to draw the actor.
 
void setAlpha (float alpha) override
 Sets the alpha value used to draw the actor.
 
virtual void setDeathEffect (const std::string &effectFile, char conditions)
 
- Public Member Functions inherited from Actor
 Actor ()
 
virtual ~Actor ()
 
const VectorgetPosition () const
 Returns the pixel position of this actor.
 
virtual void setPosition (const Vector &pos)
 Sets the pixel position of this actor.
 
int getPixelX () const
 Returns the pixels X coordinate of the actor.
 
int getPixelY () const
 Returns the pixel Y coordinate of the actor.
 
virtual int getDrawOrder () const
 Returns the pixel Y coordinate that the actor should be drawn at.
 
virtual int getTileX () const
 Returns the x coordinate in tiles of the actor.
 
virtual int getTileY () const
 Returns the y coordinate in tiles of the actor.
 
virtual void setMap (Map *map)
 
MapgetMap () const
 

Static Public Member Functions

static void setupEngine ()
 Gives a particle the properties of an engine root particle and loads the particle-related config settings.
 

Static Public Attributes

static const float PARTICLE_SKY = 800.0f
 Maximum Z position of particles.
 
static int fastPhysics = 0
 Mode of squareroot calculation.
 
static int particleCount = 0
 Current number of particles.
 
static int maxCount = 0
 Maximum number of particles.
 
static int emitterSkip = 1
 Duration of pause between two emitter updates in ticks.
 
static bool enabled = true
 true when non-crucial particle effects are disabled
 

Protected Member Functions

float getCurrentAlpha () const
 Calculates the current alpha transparency taking current fade status into account.
 

Protected Attributes

float mAlpha = 1.0f
 Opacity of the graphical representation of the particle.
 
int mLifetimeLeft = -1
 Lifetime left in game ticks.
 
int mLifetimePast = 0
 Age of the particle in game ticks.
 
int mFadeOut = 0
 Lifetime in game ticks left where fading out begins.
 
int mFadeIn = 0
 Age in game ticks where fading in is finished.
 
Vector mVelocity
 Speed in pixels per game-tick.
 
- Protected Attributes inherited from Actor
MapmMap = nullptr
 
Vector mPos
 Position in pixels relative to map.
 

Private Attributes

AliveStatus mAlive = ALIVE
 Is the particle supposed to be drawn and updated?
 
bool mAutoDelete = true
 May the particle request its deletion by the parent particle?
 
Emitters mChildEmitters
 List of child emitters.
 
Particles mChildParticles
 List of particles controlled by this particle.
 
bool mAllowSizeAdjust = false
 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 = 0
 Bitfield of death conditions which trigger spawning of the death particle.
 
float mGravity = 0.0f
 Downward acceleration in pixels per game-tick.
 
int mRandomness = 0
 Ammount of random vector change.
 
float mBounce = 0.0f
 How much the particle bounces off when hitting the ground.
 
bool mFollow = false
 is this particle moved when its parent particle moves?
 
ParticlemTarget = nullptr
 The particle that attracts this particle.
 
float mAcceleration = 0.0f
 Acceleration towards the target particle in pixels per game-tick.
 
float mInvDieDistance = -1.0f
 Distance in pixels from the target particle that causes the destruction of the particle.
 
float mMomentum = 1.0f
 How much speed the particle retains after each game tick.
 

Detailed Description

A particle spawned by a ParticleEmitter.

Definition at line 41 of file particle.h.

Member Enumeration Documentation

◆ AliveStatus

Enumerator
ALIVE 
DEAD_TIMEOUT 
DEAD_FLOOR 
DEAD_SKY 
DEAD_IMPACT 
DEAD_OTHER 
DEAD_LONG_AGO 

Definition at line 44 of file particle.h.

Constructor & Destructor Documentation

◆ Particle()

Particle::Particle ( Map map)

Constructor.

Parameters
mapthe map this particle will add itself to, may be NULL

Definition at line 57 of file particle.cpp.

◆ ~Particle()

Particle::~Particle ( )
override

Definition at line 63 of file particle.cpp.

Member Function Documentation

◆ addEffect()

Particle * Particle::addEffect ( const std::string &  particleEffectFile,
int  pixelX,
int  pixelY,
int  rotation = 0 
)

Creates a child particle that hosts some emitters described in the particleEffectFile.

Definition at line 249 of file particle.cpp.

◆ addEmitter()

void Particle::addEmitter ( ParticleEmitter emitter)
inline

Adds an emitter to the particle.

Definition at line 128 of file particle.h.

◆ addTextRiseFadeOutEffect()

Particle * Particle::addTextRiseFadeOutEffect ( const std::string &  text,
int  x,
int  y,
const gcn::Color *  color,
gcn::Font *  font,
bool  outline = false 
)

Creates a standalone text particle.

Definition at line 383 of file particle.cpp.

◆ addTextSplashEffect()

Particle * Particle::addTextSplashEffect ( const std::string &  text,
int  x,
int  y,
const gcn::Color *  color,
gcn::Font *  font,
bool  outline = false 
)

Creates a standalone text particle.

Definition at line 364 of file particle.cpp.

◆ adjustEmitterSize()

void Particle::adjustEmitterSize ( int  w,
int  h 
)

Changes the size of the emitters so that the effect fills a rectangle of this size.

Definition at line 401 of file particle.cpp.

◆ clear()

void Particle::clear ( )

Deletes all child particles and emitters.

Definition at line 423 of file particle.cpp.

◆ createChild()

Particle * Particle::createChild ( )

Creates a blank particle as a child of the current particle Useful for creating target particles.

Definition at line 242 of file particle.cpp.

◆ disableAutoDelete()

void Particle::disableAutoDelete ( )
inline

After calling this function the particle will only request deletion when kill() is called.

Definition at line 247 of file particle.h.

◆ doesFollow()

bool Particle::doesFollow ( ) const
inline

Gets the flag if the particle is supposed to be moved by its parent.

Definition at line 201 of file particle.h.

◆ draw()

bool Particle::draw ( Graphics graphics,
int  offsetX,
int  offsetY 
) const
overridevirtual

Draws the particle image.

Implements Actor.

Reimplemented in TextParticle.

Definition at line 80 of file particle.cpp.

◆ drawnWhenBehind()

bool Particle::drawnWhenBehind ( ) const
inlineoverridevirtual

Do not draw particles when behind other objects.

Reimplemented from Actor.

Reimplemented in TextParticle.

Definition at line 95 of file particle.h.

◆ getAlpha()

float Particle::getAlpha ( ) const
inlineoverridevirtual

Returns the current alpha value used to draw the actor.

Implements Actor.

Definition at line 250 of file particle.h.

◆ getCurrentAlpha()

float Particle::getCurrentAlpha ( ) const
protected

Calculates the current alpha transparency taking current fade status into account.

Definition at line 410 of file particle.cpp.

◆ isAlive()

bool Particle::isAlive ( ) const
inline

Definition at line 228 of file particle.h.

◆ isExtinct()

bool Particle::isExtinct ( ) const
inline

Determines whether the particle and its children are all dead.

Definition at line 234 of file particle.h.

◆ kill()

void Particle::kill ( )
inline

Manually marks the particle for deletion.

Definition at line 240 of file particle.h.

◆ moveBy()

void Particle::moveBy ( const Vector change)

Changes the particle position relative.

Definition at line 228 of file particle.cpp.

◆ moveTo() [1/2]

void Particle::moveTo ( const Vector pos)
inline

Sets the position in 3 dimensional space in pixels relative to map.

Definition at line 134 of file particle.h.

◆ moveTo() [2/2]

void Particle::moveTo ( float  x,
float  y 
)

Sets the position in 2 dimensional space in pixels relative to map.

Definition at line 237 of file particle.cpp.

◆ setAllowSizeAdjust()

void Particle::setAllowSizeAdjust ( bool  adjust)
inline

Definition at line 225 of file particle.h.

◆ setAlpha()

void Particle::setAlpha ( float  alpha)
inlineoverridevirtual

Sets the alpha value used to draw the actor.

Implements Actor.

Definition at line 253 of file particle.h.

◆ setBounce()

void Particle::setBounce ( float  bouncieness)
inline

Sets the ammount of velocity particles retain after hitting the ground.

Definition at line 189 of file particle.h.

◆ setDeathEffect()

virtual void Particle::setDeathEffect ( const std::string &  effectFile,
char  conditions 
)
inlinevirtual

Definition at line 255 of file particle.h.

◆ setDestination()

void Particle::setDestination ( Particle target,
float  accel,
float  moment 
)
inline

Makes the particle move toward another particle with a given acceleration and momentum.

Definition at line 208 of file particle.h.

◆ setDieDistance()

void Particle::setDieDistance ( float  dist)
inline

Sets the distance in pixel the particle can come near the target particle before it is destroyed.

Does only make sense after a target particle has been set using setDestination.

Definition at line 216 of file particle.h.

◆ setFadeIn()

void Particle::setFadeIn ( int  fadeIn)
inline

Sets the remaining particle lifetime where the particle starts to fade out.

Definition at line 164 of file particle.h.

◆ setFadeOut()

void Particle::setFadeOut ( int  fadeOut)
inline

Sets the age of the pixel in game ticks where the particle has faded in completely.

Definition at line 157 of file particle.h.

◆ setFollow()

void Particle::setFollow ( bool  follow)
inline

Sets the flag if the particle is supposed to be moved by its parent.

Definition at line 195 of file particle.h.

◆ setGravity()

void Particle::setGravity ( float  gravity)
inline

Sets the downward acceleration.

Definition at line 176 of file particle.h.

◆ setLifetime()

void Particle::setLifetime ( int  lifetime)
inline

Sets the time in game ticks until the particle is destroyed.

Definition at line 150 of file particle.h.

◆ setRandomness()

void Particle::setRandomness ( int  r)
inline

Sets the ammount of random vector changes.

Definition at line 182 of file particle.h.

◆ setupEngine()

void Particle::setupEngine ( )
static

Gives a particle the properties of an engine root particle and loads the particle-related config settings.

Definition at line 71 of file particle.cpp.

◆ setVelocity()

void Particle::setVelocity ( float  x,
float  y,
float  z 
)
inline

Sets the current velocity in 3 dimensional space.

Definition at line 170 of file particle.h.

◆ update()

bool Particle::update ( )
virtual

Updates particle position, returns false when the particle should be deleted.

Reimplemented in AnimationParticle, and RotationalParticle.

Definition at line 85 of file particle.cpp.

Member Data Documentation

◆ emitterSkip

int Particle::emitterSkip = 1
static

Duration of pause between two emitter updates in ticks.

Definition at line 58 of file particle.h.

◆ enabled

bool Particle::enabled = true
static

true when non-crucial particle effects are disabled

Definition at line 59 of file particle.h.

◆ fastPhysics

int Particle::fastPhysics = 0
static

Mode of squareroot calculation.

Definition at line 55 of file particle.h.

◆ mAcceleration

float Particle::mAcceleration = 0.0f
private

Acceleration towards the target particle in pixels per game-tick.

Definition at line 289 of file particle.h.

◆ mAlive

AliveStatus Particle::mAlive = ALIVE
private

Is the particle supposed to be drawn and updated?

Definition at line 272 of file particle.h.

◆ mAllowSizeAdjust

bool Particle::mAllowSizeAdjust = false
private

Can the effect size be adjusted by the object props in the map file?

Definition at line 277 of file particle.h.

◆ mAlpha

float Particle::mAlpha = 1.0f
protected

Opacity of the graphical representation of the particle.

Definition at line 260 of file particle.h.

◆ mAutoDelete

bool Particle::mAutoDelete = true
private

May the particle request its deletion by the parent particle?

Definition at line 274 of file particle.h.

◆ maxCount

int Particle::maxCount = 0
static

Maximum number of particles.

Definition at line 57 of file particle.h.

◆ mBounce

float Particle::mBounce = 0.0f
private

How much the particle bounces off when hitting the ground.

Definition at line 284 of file particle.h.

◆ mChildEmitters

Emitters Particle::mChildEmitters
private

List of child emitters.

Definition at line 275 of file particle.h.

◆ mChildParticles

Particles Particle::mChildParticles
private

List of particles controlled by this particle.

Definition at line 276 of file particle.h.

◆ mDeathEffect

std::string Particle::mDeathEffect
private

Particle effect file to be spawned when the particle dies.

Definition at line 278 of file particle.h.

◆ mDeathEffectConditions

char Particle::mDeathEffectConditions = 0
private

Bitfield of death conditions which trigger spawning of the death particle.

Definition at line 279 of file particle.h.

◆ mFadeIn

int Particle::mFadeIn = 0
protected

Age in game ticks where fading in is finished.

Definition at line 268 of file particle.h.

◆ mFadeOut

int Particle::mFadeOut = 0
protected

Lifetime in game ticks left where fading out begins.

Definition at line 267 of file particle.h.

◆ mFollow

bool Particle::mFollow = false
private

is this particle moved when its parent particle moves?

Definition at line 285 of file particle.h.

◆ mGravity

float Particle::mGravity = 0.0f
private

Downward acceleration in pixels per game-tick.

Definition at line 282 of file particle.h.

◆ mInvDieDistance

float Particle::mInvDieDistance = -1.0f
private

Distance in pixels from the target particle that causes the destruction of the particle.

Definition at line 290 of file particle.h.

◆ mLifetimeLeft

int Particle::mLifetimeLeft = -1
protected

Lifetime left in game ticks.

Definition at line 265 of file particle.h.

◆ mLifetimePast

int Particle::mLifetimePast = 0
protected

Age of the particle in game ticks.

Definition at line 266 of file particle.h.

◆ mMomentum

float Particle::mMomentum = 1.0f
private

How much speed the particle retains after each game tick.

Definition at line 291 of file particle.h.

◆ mRandomness

int Particle::mRandomness = 0
private

Ammount of random vector change.

Definition at line 283 of file particle.h.

◆ mTarget

Particle* Particle::mTarget = nullptr
private

The particle that attracts this particle.

Definition at line 288 of file particle.h.

◆ mVelocity

Vector Particle::mVelocity
protected

Speed in pixels per game-tick.

Definition at line 269 of file particle.h.

◆ PARTICLE_SKY

const float Particle::PARTICLE_SKY = 800.0f
static

Maximum Z position of particles.

Definition at line 54 of file particle.h.

◆ particleCount

int Particle::particleCount = 0
static

Current number of particles.

Definition at line 56 of file particle.h.


The documentation for this class was generated from the following files: