Game Development Reference
In-Depth Information
CollisionObj = m_Weapon.CheckAmmoCollision(m_Cube);
if (CollisionObj != null)
{
CollisionObj.ApplyLinearImpulse(m_Cube);
m_Score = m_Score + m_Cube.GetObjectStats().GetKillValue();
}
float ExplosionMinVelocity = 0.02f;
float ExplosionMaxVelocity = 0.4f;
//Check Collision with Cube2
Physics.CollisionStatus result = m_Pyramid.CheckCollision(m_Cube2);
if ((result == Physics.CollisionStatus.COLLISION) ||
(result == Physics.CollisionStatus.PENETRATING_COLLISION))
{
m_Pyramid.ExplodeObject(ExplosionMaxVelocity, ExplosionMinVelocity);
m_Pyramid.PlayExplosionSFX();
m_Pyramid.ApplyLinearImpulse(m_Cube2);
// Set Pyramid Velocity and Acceleration to 0
m_Pyramid.GetObjectPhysics().ResetState();
m_Pyramid.TakeDamage(m_Cube2);
}
}
Modifying the onDrawFrame() Function
The onDrawFrame() function must also be modified in order to render and update the player's view,
graphic, and weapons. (See Listing 7-64.)
The following modifications have to be made:
1.
The collisions between the player's ammunition and the two cubes and the
collision between the cubes and the player's pyramid must all be processed.
2.
If the camera has moved, this movement must be processed.
3.
The player's power pyramid must be updated and drawn.
4.
If the user has touched the screen, you must process the touch and fire the
player's weapon.
5.
Update and draw the player's weapon and ammunition.
Listing 7-64. 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);
 
Search WWH ::




Custom Search