Game Development Reference
In-Depth Information
...
Draw the particle as a small circle...
...
Explosion.p[i].Active = UpdateParticleState(&(Explosion.p[i]),
10);
}
}
if(finished)
Explosion.Active = FALSE;
return !finished;
}
//---------------------------------------------------------------------------//
/* This is generic function to update the state of a given particle.
p: pointer to a particle structure
dtime: time increment in milliseconds to
advance the state of the particle
If the total elapsed time for this particle has exceeded the particle's
set life, then this function returns FALSE, indicating that the particle
should expire.
*/
BOOL UpdateParticleState(TParticle* p, int dtime)
{
BOOL retval;
float t;
p->time+=dtime;
t = (float)p->time/1000.0f;
p->x = p->vi * cos(p->angle*PI/180.0f) * t;
p->y = p->vi * sin(p->angle*PI/180.0f) * t + (p->gravity*t*t)/2.0f;
if (p->time >= p->life)
retval = FALSE;
else
retval = TRUE;
return retval;
}
UpdateParticleState uses the kinematic formulas that we've already shown you to
update the particle's position as a function of its initial velocity, time, and the acceleration
due to gravity. After UpdateParticleState is called, DrawParticleExplosion scales
down each particle's color, fading it to black, based on the life of each particle and elapsed
time. The fade effect is simply to show the particles dying slowly over time instead of
disappearing from the screen. The effect resembles the behavior of fireworks as they
explode in the night sky.
Search Nedrilad ::




Custom Search