Game Development Reference
In-Depth Information
Listing 8-3. Playing the Explosion Sound Effect
void PlayExplosionSFX()
{
if (m_ExplosionSFXIndex >= 0)
{
PlaySound(m_ExplosionSFXIndex);
}
}
The CreateHitGroundSFX() function creates a new sound effect by calling the AddSound() function in
the Object3d class with the resource id of the sound effect and the sound pool in which the sound
will be stored. The index to the newly created sound is returned and put in m_HitGroundSFXIndex .
(See Listing 8-4.)
Listing 8-4. Creating the Hit Ground Sound Effect
void CreateHitGroundSFX(SoundPool Pool, int ResourceID)
{
m_HitGroundSFXIndex = AddSound(Pool, ResourceID);
}
The PlayHitGoundSFX() function plays the sound effect for the arena object hitting the ground,
if there is one. (See Listing 8-5.)
Listing 8-5. Playing the Hit Ground Sound Effect
void PlayHitGoundSFX()
{
if (m_HitGroundSFXIndex >= 0)
{
PlaySound(m_HitGroundSFXIndex);
}
}
The RenderArenaObject() function draws the arena object to the screen. It also tests to see if the
object has just hit the ground. If it has just hit the ground, the hit ground sound effect is played, and
the hit ground status in the Physics class is reset. (See Listing 8-6.)
Listing 8-6. Rendering the Arena Object
void RenderArenaObject(Camera Cam, PointLight light)
{
// Object hits ground
boolean ShakeCamera = GetObjectPhysics().GetHitGroundStatus();
if (ShakeCamera)
{
GetObjectPhysics().ClearHitGroundStatus();
PlayHitGoundSFX();
}
DrawObject(Cam, light);
}
 
Search WWH ::




Custom Search