Game Development Reference
In-Depth Information
Particle Explosions
For most in-game explosions, it will be sufficient to implement a particle-type explosion
that we covered way back in Chapter 2 . Now, in Chapter 2 the particles were simply
dots, but they don't have to be limited to such simple sprites. In some cases, such as
sparks from a bullet hitting a metal container, it would be very accurate to model ex‐
plosions as particles; however, by making our particles look like bits of cars, we can also
make it appear that the car itself exploded. The reason this is easier is because the particle
explosions don't have any angular motion. Although you can assign different parts of
the cars to different particles, when they fly off due to the explosion, they won't be
rotating. The good news is that a particle explosion will still give you a realistic distri‐
bution of fragments of something on the ground.
To talk about how to link bullets and particle explosions in detail, we'll consider some‐
thing more physically accurate than a bullet blowing up a car. Let's consider a bullet
hitting some loose gravel. This will generally cause the gravel to be thrown up into the
air from the bullet collision. Instead of trying to calculate the complex collisions during
impact, we'll generate a particle explosion based on the code in Chapter 2 :
void CreateParticleExplosion(int x, int y, int Vinit, int life,
float gravity, float angle)
int i;
int m;
float f;
Explosion.Active = TRUE;
Explosion.x = x;
Explosion.y = y;
Explosion.V0 = Vinit;
for(i=0; i<_MAXPARTICLES; i++)
Explosion.p[i].x = 0;
Explosion.p[i].y = 0;
Explosion.p[i].vi = tb_Rnd(Vinit/2, Vinit);
if(angle < 999)
if(tb_Rnd(0,1) == 0)
m = −1;
m = 1;
Explosion.p[i].angle = -angle + m * tb_Rnd(0,10);
} else
Explosion.p[i].angle = tb_Rnd(0,360);
f = (float) tb_Rnd(80, 100) / 100.0f;
Search Nedrilad ::

Custom Search