Game Development Reference
In-Depth Information
Figure 2-7. Particle explosion example program
The explosion effect takes place in the large rectangular area on the right. While the
black dots representing exploding particles are certainly static in the figure, we assure
you they move in the most spectacular way during the simulation.
In the edit controls on the left, you specify an x- and y-position for the effect, along with
the initial velocity of the particles (which is a measure of the explosion's strength), a
duration in milliseconds, a gravity factor, and finally an angle. The angle parameter can
be any number between 0 and 360 degrees or 999. When you specify an angle in the
range of 0 to 360 degrees, all the particles in the explosion will be launched generally in
that direction. If you specify a value of 999, then all the particles will shoot off in random
directions. The duration parameter is essentially the life of the effect. The particles will
fade out as they approach that life.
The first thing you need to do for this example is set up some structures and global
variables to represent the particle effect and the individual particles making up the effect
along with the initial parameters describing the behavior of the effect as discussed in
the previous paragraph. Here's the code:
// Define a custom type to represent each particle in the effect.
typedef struct _TParticle
float x; // x coordinate of the particle
Search Nedrilad ::

Custom Search