Game Development Reference
In-Depth Information
BOOL Active; // indicates whether this particle
float mass; //for calculating the particle's energy
} TParticle;
#define _MAXPARTICLES 50
#define _MASSOFPARTICLE .25
typedef struct _TParticleExplosion
{
TParticle p[_MAXPARTICLES]; // list of particles
// making up this effect
int x; // initial x location
int y; // initial y location
float KE; //Available kinect energy
float
BOOL Active; // indicates whether this effect is
} TParticleExplosion;
Notice that V0 is no longer required, as the available kinetic energy will govern the
strength of the explosion. Assuming that the bullet's kinetic energy is given as a variable
KEb , our new CreateParticleExplosion function would look like the following:
void CreateParticleExplosion(int x, int y, int KEb, int life,
float gravity, float angle)
{
int i;
int m;
float f;
Explosion.Active = TRUE;
Explosion.x = x;
Explosion.y = y;
Explosion.KE = KEb;
for(i=0; i<_MAXPARTICLES; i++)
{
Explosion.p[i].x = 0;
Explosion.p[i].y = 0;
Explosion.p[i].m = _MASSOFPARTICLE; //Mass of a single gravel
Explosion.p[i].vi = tb_Rnd(0, sqrt(Explosion.KE/(_MASSOFPARTICLE*
_MAXPARTICLES));
Explosion.KE = Explosion.KE - ((1/2)*(Explosion.p[i].m)*
(Explosion.p[i].vi));
if(angle < 999)
{
if(tb_Rnd(0,1) == 0)
m = −1;
else
m = 1;

Custom Search