Game Development Reference
In-Depth Information
boolean ExplosionFinished = true;
for (int i = 0; i < m_NumberParticles; i++)
{
// If all Particles are not active then explosion is finished.
if (m_Particles[i].GetActiveStatus() == true)
{
// If Color Animation is on then set particle to random color
if(m_ParticleColorAnimation)
{
m_Particles[i].SetColor(GenerateRandomColor());
}
// For each particle update particle
m_Particles[i].UpdateParticle(System.currentTimeMillis());
ExplosionFinished = false;
}
}
if (ExplosionFinished)
{
m_ExplosionActive = false;
}
}
Modifying the Object3d Class
Next, we have to add some code to our Object3d class, so it can use the explosions.
The MAX_EXPLOSIONS variable holds the maximum number of explosions associated with this object.
private int MAX_EXPLOSIONS = 3;
The m_NumberExplosions variable holds the actual number of explosions associated with this object.
private int m_NumberExplosions = 0;
The m_Explosions variable holds references to the SphericalPolygonExplosion objects associated
with this object, if any.
private SphericalPolygonExplosion[] m_Explosions = new SphericalPolygonExplosion[MAX_EXPLOSIONS];
We also add the functions RenderExplosions() , to render explosions; UpdateExplosions() , to
update explosions; and ExplodeObject() , to start explosions. These functions are fairly simple,
so in the interest of saving space, please refer to the Source Code/Download area for this chapter
at apress.com for the full details.
The DrawObject() function must be modified to render the explosions, by calling the
RenderExplosions() function. (See Listing 7-50.)
 
Search WWH ::




Custom Search