Game Development Reference
In-Depth Information
Finally, new code has to be added to create the player's weapon in the onSurfaceCreated() function.
CreateWeapon(m_Context);
New code also has to be added to create the sound effects for the weapon.
CreatePlayerWeaponSound(m_Context);
Processing Collisions
The ProcessCollisions() function processes collisions between game objects.
The ProcessCollisions() function (see Listing 7-63) does the following:
Checks for collision between the player's ammunition and m_Cube2 . If there
is a collision, then it applies a linear force to the two colliding objects and
increases the player's score by the kill value of m_Cube2 .
1.
Checks for collision between the player's ammunition and m_Cube . If there is
a collision, it applies a linear force to the two colliding objects and increases
the player's score by the kill value of m_Cube .
2.
Checks for a collision between the player's pyramid and m_Cube2 , which is
the cube in front of the pyramid.
3.
4.
If there is a collision, it
a. Starts the explosion associated with the pyramid
b. Plays the explosion sound effect associated with the pyramid
c. Applies the linear impulse to both objects
d. Resets the pyramid state to eliminate any accelerations, because the
pyramid is stationary
e.
Calculates the damage to the pyramid
Listing 7-63. Processing the Game Object Collisions
void ProcessCollisions()
{
Object3d CollisionObj = m_Weapon.CheckAmmoCollision(m_Cube2);
if (CollisionObj != null)
{
CollisionObj.ApplyLinearImpulse(m_Cube2);
m_Score = m_Score + m_Cube2.GetObjectStats().GetKillValue();
}
 
Search WWH ::




Custom Search