Game Development Reference
In-Depth Information
Next, we need to change the code to roll over the health back to 100 when it reaches 0.
(See Listing 6-51.)
Listing 6-51. Rolling over the Health
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 = 100;
}
m_Score = m_Score + 10;
}
Modifying the MyGLSurfaceView Class
We must also modify the MyGLSurfaceView class.
Add a line that holds a reference to the Custom GLRenderer.
public MyGLRenderer CustomGLRenderer = null;
Next, we have to make some changes to the constructor. (See Listing 6-52.)
Listing 6-52. MyGLSurfaceView Constructor Modifications
public MyGLSurfaceView(Context context)
{
super(context);
// Create an OpenGL ES 2.0 context.
setEGLContextClientVersion(2);
// Set the Renderer for drawing on the GLSurfaceView
//setRenderer(new MyGLRenderer(context));
CustomGLRenderer = new MyGLRenderer(context);
setRenderer(CustomGLRenderer);
}
 
Search WWH ::




Custom Search