Game Development Reference
In-Depth Information
Next, we must modify the onDrawFrame() function, to play the collision sounds associated with each
of the cubes. Each cube plays its own explosion sound through the PlaySound() function, using the
sound index associated with the sound. See the highlighted code in Listing 6-10.
Listing 6-10. Modifying the onDrawFrame() function
@Override
public void onDrawFrame(GL10 unused)
{
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
m_Camera.UpdateCamera();
////////////////////////// Update Object Physics
// Cube1
m_Cube.UpdateObject3d();
boolean HitGround = m_Cube.GetObjectPhysics().GetHitGroundStatus();
if (HitGround)
{
m_Cube.GetObjectPhysics().ApplyTranslationalForce(m_Force1);
m_Cube.GetObjectPhysics().ApplyRotationalForce(m_RotationalForce, 10.0f);
m_Cube.GetObjectPhysics().ClearHitGroundStatus();
}
// Cube2
m_Cube2.UpdateObject3d();
// Process Collisions
Physics.CollisionStatus TypeCollision =
m_Cube.GetObjectPhysics().CheckForCollisionSphereBounding(m_Cube, m_Cube2);
if ((TypeCollision == Physics.CollisionStatus.COLLISION) ||
(TypeCollision == Physics.CollisionStatus.PENETRATING_COLLISION))
{
m_Cube.GetObjectPhysics().ApplyLinearImpulse(m_Cube, m_Cube2);
// SFX
m_Cube.PlaySound(m_SoundIndex1);
m_Cube2.PlaySound(m_SoundIndex2);
}
//////////////////////////// Draw Objects
m_Cube.DrawObject(m_Camera, m_PointLight);
m_Cube2.DrawObject(m_Camera, m_PointLight);
////////////////////////// Update and Draw Grid
UpdateGravityGrid();
m_Grid.DrawGrid(m_Camera);
}
The final task is to run our project. You should hear the collision sounds play each time the cubes
hit each other.
 
Search WWH ::




Custom Search