Game Development Reference
In-Depth Information
Here you can see that all the particles are set to start off in the same position, as specified
by the x and y coordinates that you provide; however, you'll notice that the initial velocity
of each particle is actually randomly selected from a range of Vinit/2 to Vinit . We do
this to give the particle behavior some variety. We do the same thing for the life param‐
eter of each particle so they don't all fade out and die at the exact same time.
After the particle explosion is created, the program enters a loop to propagate and draw
the effect. The loop is a while loop, as shown here in pseudocode:
Clear the off screen buffer...
status = DrawParticleExplosion( );
Copy the off screen buffer to the screen...
The while loop continues as long as status remains true , which indicates that the
particle effect is still alive. After all the particles in the effect reach their set life, then the
effect is dead and status will be set to false . All the calculations for the particle behavior
actually take place in the function called DrawParticleExplosion ; the rest of the code
in this while loop is for clearing the off-screen buffer and then copying it to the main
DrawParticleExplosion updates the state of each particle in the effect by calling an‐
other function, UpdateParticleState , and then draws the effect to the off-screen buffer
passed in as a parameter. Here's what these two functions look like:
// Draws the particle system and updates the state of each particle.
// Returns false when all of the particles have died out.
BOOL DrawParticleExplosion(void)
int i;
BOOL finished = TRUE;
float r;
for(i=0; i<_MAXPARTICLES; i++)
finished = FALSE;
// Calculate a color scale factor to fade the particle's color
// as its life expires
r = ((float)(Explosion.p[i].life-
Search Nedrilad ::

Custom Search