Game Development Reference
In-Depth Information
// Create SFX
CreateSoundPool();
CreateSound(m_Context);
// Create HUD
// Get Width and Height of surface
m_ViewPortHeight = m_Context.getResources().getDisplayMetrics().heightPixels;
m_ViewPortWidth = m_Context.getResources().getDisplayMetrics().widthPixels;
SetupCamera();
// Create Character Set
CreateCharacterSet(m_Context);
CreateHUD
}
The onDrawFrame() function has to be modified to accommodate our HUD. We have added code that
will decrease the health and increase the score on the HUD every time the two cubes collide with
each other. We have also added code to update the numeric values on the HUD, update the HUD,
and render the HUD to the screen. (See Listing 6-44.)
Listing 6-44. Modifying the onDrawFrame() Function
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);
// HUD
m_Health = m_Health - 1;
if (m_Health < 0)
{
m_Health = 0;
}
m_Score = m_Score + 10;
}
///////////////////////// HUD
UpdateHUD();
m_HUD.UpdateHUD(m_Camera);
m_HUD.RenderHUD(m_Camera, m_PointLight);
Now, run the application, and you should see the HUD with the score increasing and the health
decreasing every time the two cubes collide. You should see something similar to Figure 6-1 , shown
earlier in this chapter.
Search WWH ::




Custom Search