The Game Engine  1
ParticleSystem Class Reference

Particle System manager. More...

#include <ParticleSystem.h>

+ Inheritance diagram for ParticleSystem:
+ Collaboration diagram for ParticleSystem:

Classes

class  Particle
 Particle System manager. More...
 

Public Member Functions

 ParticleSystem (string name, Point2D position, Texture tex, vector< CollisionObject * > collisionBounds=vector< CollisionObject * >())
 Creates a new particle system with the specified name at the specified position with the specified frame as the animation. More...
 
 ~ParticleSystem ()
 
void SetTexture (Actor actor, int animation, int frame)
 Sets a texture to a particle system's particles from a pre-loaded frame already attached to an actor. More...
 
void SetTexture (SpriteFrame *frame)
 Sets a texture to a particle system's particles from a pre-loaded frame. More...
 
void SpawnParticles (int numparticles)
 Spawns a number of new particles into the particle system. More...
 
virtual void draw ()
 Draws the thing. More...
 
virtual void drawCollisions ()
 Draws collision bounds as well as the ObjectBounds. More...
 
void update ()
 This updates the internal particle system's Physics and state (i.e. More...
 
virtual void runBehavior ()
 This runs the system's behavior as well as that of the children. More...
 
vector< Sprite * > collisionWithSprites (string name, int count=-1)
 Checks for collision with sprite of a given name. More...
 
vector< CollisionObject * > & getCollisionData ()
 Returns collision data. More...
 
Point2D getBasePos ()
 Obtain base position. More...
 
Point2D getCenterPos ()
 Obtain Center Pos for Collisions. More...
 
virtual WorldObjectType getType ()
 This provides a simple interface to determine types of objects. More...
 
- Public Member Functions inherited from WorldObject
 WorldObject (std::string name, Point2D pos=Point2D(), int z=0)
 
void drawCollisions (vector< CollisionObject * > &vec, const Point2D &pos)
 Draws CollisionObject data for the Object. More...
 
void setPosition (double x, double y)
 Sets the WorldObject's x an y coordinate. More...
 
void setPosition (Point2D pos)
 Sets the WorldObject's x an y coordinate. More...
 
void setBasePosition (double x, double y)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void setBasePosition (Point2D pos)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void setCenterPosition (double x, double y)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void setCenterPosition (Point2D pos)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void move (double dx=0.0, double dy=0.0)
 Move by given amount NOTE: This is an instantaneous movement by a given amount and does not correspond to physics which is set to do the updated amount per second. More...
 
virtual void move (Point2D direction)
 Moves the WorldObject relative to the current pos. More...
 
virtual void moveTowards (Point2D direction)
 Move towards a given coordinate (path finding) More...
 
Point2D getPosition ()
 Gets the WorldObject's position. More...
 
void setTransparency (float f)
 Sets the WorldObject's transparency. More...
 
float getTransparency ()
 Gets the WorldObject's transparency. More...
 
void setAngle (float a)
 Sets the WorldObject's angle in degrees. More...
 
float getAngle ()
 Gets the WorldObject's angle. More...
 
void setVelocity (Point2D vel)
 Sets the WorldObject's velocity as a vector (will set MaxVelocity if needed) More...
 
void setVelocity (double xVel, double yVel)
 Sets the WorldObject's velocity from coordinates (will set MaxVelocity if needed) More...
 
Point2D getVelocity ()
 Gets the WorldObject's Velocity. More...
 
void setMaxVelocity (Point2D vel)
 Sets the WorldObject's MaxVelocity (magnitude) from (x,y) and transforms into a magnitude. More...
 
void setMaxVelocity (double vel, Point2D dir)
 Sets the WorldObject's MaxVelocity (magnitude) value in the direction specified. More...
 
void setMaxSpeed (double vel)
 Sets the WorldObject's MaxVelocity (magnitude) value in the direction specified. More...
 
Point2D getMaxVelocity ()
 Gets the WorldObject's Max Velocity. More...
 
double getMaxSpeed ()
 Gets the WorldObject's Max Speed. More...
 
double getMaxSpeedSquared ()
 Gets the WorldObject's Max Speed Squared (cheaper operation). More...
 
void setAcceleration (Point2D accel)
 Sets the WorldObject's Acceleration in (x,y) coords. More...
 
Point2D getAcceleration ()
 Gets the WorldObject's Acceleration. More...
 
void setZOrder (int i)
 
int getZOrder ()
 
std::string getName ()
 returns the WorldObject's name More...
 
bool operator< (WorldObject &rhs)
 Sort worldObjects. More...
 

Public Attributes

Behavior ParticleInit
 Sets a behavior function to be run on each particle once when it is spawned. More...
 
Behavior ParticleUpdate
 Sets a behavior function to be run on each particle every game loop. More...
 
bool CollisionEnabled
 Gets or sets whether the particle system has collision checking enabled. More...
 
int CollisionList
 Gets or sets the particle system's collision display list. More...
 

Protected Attributes

list< Particle * > mParticles
 Particles this System has generated. More...
 
CollisionRectangle mBoundingBox
 System's collision box for autoCollisions. More...
 
vector< CollisionObject * > mCollisionData
 Collision boundaries provided by user. More...
 
Texture mTexture
 Image to draw. More...
 
- Protected Attributes inherited from WorldObject
std::string mName
 WorldObject's name. More...
 
Point2D mPos
 The current (x,y) position. More...
 
Point2D mVelocity
 The current velocity vector. More...
 
Point2D mMaxVelocity
 The max velocity is the max possible velocity where lengthis the speed. More...
 
double mMaxSpeed
 The max Speed if MaxVelocity is 0 to store val. More...
 
Point2D mAcceleration
 The current acceleration vector. More...
 
bool mVisible
 Determine if Object should be visible. More...
 
float mTransparency
 Transparency! More...
 
float mAngle
 Angle of rotation. More...
 
float mScale
 Scale for the sprit. More...
 
int ZOrder
 Stacking order. Determines what draws on top. (subsorted by position) More...
 
long mLastUpdate
 Number that indicates when the Object has last updated. Overflows in about 24 days so no worries. More...
 
long mLastDraw
 Number that indicates when the Object has last updated. Overflows in about 24 days so no worries. More...
 
bool mUnused
 Determines whether or not this object's update function should run. More...
 
Behavior mBehavior
 Behavior to act each loop if !mUnused. More...
 

Additional Inherited Members

- Public Types inherited from WorldObject
enum  WorldObjectType {
  SPRITE, BACKGROUND, MENU, TEXT,
  PARTICLESYSTEM
}
 This is to be used for Type checking so as to make no need for dynamic_cast and it's inefficiency. More...
 

Detailed Description

Particle System manager.

This class is tasked with the following:

  • Spawning Particles

Definition at line 18 of file ParticleSystem.h.

Constructor & Destructor Documentation

ParticleSystem::ParticleSystem ( string  name,
Point2D  position,
Texture  tex,
vector< CollisionObject * >  collisionBounds = vector<CollisionObject*>() 
)

Creates a new particle system with the specified name at the specified position with the specified frame as the animation.

ParticleSystem* p = new ParticleSystem("spawner", Point2D(15,15), g->getAnimation("sun.anim")->Frames[0]->tex);
Parameters
nameName to assign to the particle system.
positionInitial position of the particle system.
texTexture to apply
collisionBoundsBoundaries for this ParticleSystem

Definition at line 16 of file ParticleSystem.cpp.

+ Here is the call graph for this function:

ParticleSystem::~ParticleSystem ( )

Definition at line 28 of file ParticleSystem.cpp.

Member Function Documentation

vector< Sprite * > ParticleSystem::collisionWithSprites ( string  name,
int  count = -1 
)

Checks for collision with sprite of a given name.

Todo:
if vals has items in it add each of them into the marked set

Definition at line 180 of file ParticleSystem.cpp.

+ Here is the call graph for this function:

void ParticleSystem::draw ( )
virtual

Draws the thing.

Implements WorldObject.

Definition at line 59 of file ParticleSystem.cpp.

+ Here is the call graph for this function:

void ParticleSystem::drawCollisions ( )
virtual

Draws collision bounds as well as the ObjectBounds.

Reimplemented from WorldObject.

Definition at line 97 of file ParticleSystem.cpp.

+ Here is the call graph for this function:

Point2D ParticleSystem::getBasePos ( )
virtual

Obtain base position.

Implements WorldObject.

Definition at line 210 of file ParticleSystem.cpp.

Point2D ParticleSystem::getCenterPos ( )
virtual

Obtain Center Pos for Collisions.

Implements WorldObject.

Definition at line 214 of file ParticleSystem.cpp.

+ Here is the caller graph for this function:

vector< CollisionObject * > & ParticleSystem::getCollisionData ( )

Returns collision data.

Definition at line 176 of file ParticleSystem.cpp.

ParticleSystem::WorldObjectType ParticleSystem::getType ( )
virtual

This provides a simple interface to determine types of objects.

Returns the name of the Class and Descendants i.e. Something inheriting from Sprite would look like Sprite:Thing

Implements WorldObject.

Definition at line 218 of file ParticleSystem.cpp.

void ParticleSystem::runBehavior ( )
virtual

This runs the system's behavior as well as that of the children.

Reimplemented from WorldObject.

Definition at line 160 of file ParticleSystem.cpp.

+ Here is the call graph for this function:

void ParticleSystem::SetTexture ( Actor  actor,
int  animation,
int  frame 
)

Sets a texture to a particle system's particles from a pre-loaded frame already attached to an actor.

This function takes a frame from an actor and turns it into the image used for the particles in the system. Particles are drawn as squares and the image is scaled to fit them.

ParticleSystem* p = new ParticleSystem("spawner", Point2D(15,15), g->getAnimation("sun.anim")->Frames[0]->tex);
ps.SetTexture(g->getActor("sun"), ANIMATION_INDEX, FRAME_INDEX);
Parameters
actorActor that owns the animation the target frame belongs to.
animationAnimation index of the animation that the target frame is part of.
frameIndex of the target frame in the animation.

Definition at line 32 of file ParticleSystem.cpp.

+ Here is the caller graph for this function:

void ParticleSystem::SetTexture ( SpriteFrame frame)

Sets a texture to a particle system's particles from a pre-loaded frame.

ParticleSystem* p = new ParticleSystem("spawner", Point2D(15,15), g->getAnimation("sun.anim")->Frames[0]->tex);
p->SetTexture(vikings1->getAnimation());
Parameters
frameFrame to load the texture from.

Definition at line 37 of file ParticleSystem.cpp.

void ParticleSystem::SpawnParticles ( int  numparticles)

Spawns a number of new particles into the particle system.

When this function is called, the system's particle initialization function is immediately called on all of the new particles which allows their initial properties to be set immediately.

Parameters
numparticlesNumber of new particles to spawn.

Definition at line 42 of file ParticleSystem.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ParticleSystem::update ( )
virtual

This updates the internal particle system's Physics and state (i.e.

kills children)

Particle basic Physics update

generate bounding box of this system

Reimplemented from WorldObject.

Definition at line 106 of file ParticleSystem.cpp.

+ Here is the call graph for this function:

Member Data Documentation

bool ParticleSystem::CollisionEnabled

Gets or sets whether the particle system has collision checking enabled.

By default, particle systems have collisions disabled. By calling this function, collisions are enabled, allowing sprites to check for collision with the particle system. Particle systems cannot collide with other particle systems.

ParticleSystem original = Game::game()->FindParticleSystem("masterExplosion");
ParticleSystem copy = new ParticleSystem(original);
copy.Name = "explosionCopy";
copy.CollisionEnabled = true;

Definition at line 149 of file ParticleSystem.h.

int ParticleSystem::CollisionList

Gets or sets the particle system's collision display list.

Todo:
implement

The display list determines which other objects will not register collisions with the particle system. Sprites will not collide with a particle system with the same display list.

ParticleSystem original = Game::game()->FindParticleSystem("masterExplosion");
ParticleSystem copy = new ParticleSystem(original);
copy.Name = "explosionCopy";
copy.CollisionEnabled = true;
copy.DisplayList = 1;

Definition at line 166 of file ParticleSystem.h.

CollisionRectangle ParticleSystem::mBoundingBox
protected

System's collision box for autoCollisions.

Definition at line 260 of file ParticleSystem.h.

vector<CollisionObject*> ParticleSystem::mCollisionData
protected

Collision boundaries provided by user.

Definition at line 263 of file ParticleSystem.h.

list<Particle*> ParticleSystem::mParticles
protected

Particles this System has generated.

Definition at line 257 of file ParticleSystem.h.

Texture ParticleSystem::mTexture
protected

Image to draw.

Definition at line 266 of file ParticleSystem.h.

Behavior ParticleSystem::ParticleInit

Sets a behavior function to be run on each particle once when it is spawned.

Once a particle initialization function is defined, each time SpawnParticles(int) is called, that function is called with

set to the particle that has just been created.

Example of an initialization function:

// A sample particle initialization function
void ParticleInitFN()
{
Game* g = Game::game();
//rand cloud-like velocity
float randAngle = randFloat() * (float)PI * 2.0f;
int speed = randInt(1, 7);
//gets velocity from random #s
g->CurrentParticle->Velocity = getVector(randAngle, speed);
g->CurrentParticle->Position = Point2D(0, 0);//point is relative to start of particle spawnpoint
}

And here's an example of applying it:

ParticleSystem ps = new ParticleSystem("TrailingParticleSystem", new Point2D(0, 0),FindActor("BULLET").Animations[0].Frames[0]);
p->ParticleInit = Behaviors.ParticleInitFN;

Definition at line 100 of file ParticleSystem.h.

Behavior ParticleSystem::ParticleUpdate

Sets a behavior function to be run on each particle every game loop.

The particle update function is called every game loop on every particle in the particle system, setting the current particle to

in every call.

Example of an initialization function:

// A sample particle initialization function
void ParticleUpdateFN()
{
Game* g = Game::game();
//rand cloud-like velocity
float randAngle = randFloat() * (float)PI * 2.0f;
int speed = randInt(1, 7);
//gets velocity from random #s
g->CurrentParticle->Velocity = getVector(randAngle, speed);
g->CurrentParticle->Position = Point2D(0, 0);//point is relative to start of particle spawnpoint
}

And here's an example of applying it:

ParticleSystem ps = new ParticleSystem("TrailingParticleSystem", new Point2D(0, 0),FindActor("BULLET").Animations[0].Frames[0]);
p->ParticleInit = ParticleInitFN;
p->ParticleUpdate = ParticleUpdateFN;

Definition at line 134 of file ParticleSystem.h.


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