Game Development Reference
In-Depth Information
float y; // y coordinate of the particle
float vi; // initial velocity
float angle; // initial trajectory (direction)
int life; // duration in milliseconds
int r; // red component of particle's color
int g; // green component of particle's color
int b; // blue component of particle's color
int time; // keeps track of the effect's time
float gravity; // gravity factor
BOOL Active; // indicates whether this particle
// is active or dead
} TParticle;
#define _MAXPARTICLES 50
typedef struct _TParticleExplosion
TParticle p[_MAXPARTICLES]; // list of particles
// making up this effect
int V0; // initial velocity, or strength, of the effect
int x; // initial x location
int y; // initial y location
BOOL Active; // indicates whether this effect is
//active or dead
} TParticleExplosion;
// Now define the variables required for this simulation
TParticleExplosion Explosion;
int xc; // x coordinate of the effect
int yc; // y coordinate of the effect
int V0; // initial velocity
int Duration; // life in milliseconds
float Gravity; // gravity factor (acceleration)
float Angle; // indicates particles' direction
You can see from this code that the particle explosion effect is made up of a collection
of particles. The behavior of each particle is determined by kinematics and the initial
parameters set for each particle.
Whenever you press the Go button, the initial parameters that you specified are used
to initialize the particle explosion (if you press the Random button, the program ran‐
domly selects these initial values for you). This takes place in the function called Crea
teParticleExplosion :
/* This function creates a new particle explosion effect.
x,y: starting point of the effect
Vinit: a measure of how fast the particles will be sent flying
Search Nedrilad ::

Custom Search