Game Development Reference
In-Depth Information
Listing 7-26. Checking the Weapon's Ammunition Collision with an Object
Object3d CheckAmmoCollision(Object3d obj)
{
Object3d ObjectCollided = null;
for (int i = 0; i < MAX_DEFAULTAMMO; i++)
{
if (m_WeaponClip[i].IsFired() == true)
{
//Check Collision
Physics.CollisionStatus result = m_WeaponClip[i].CheckCollision(obj);
if ((result == Physics.CollisionStatus.COLLISION) ||
(result == Physics.CollisionStatus.PENETRATING_COLLISION))
{
ObjectCollided = m_WeaponClip[i];
}
}
}
return ObjectCollided;
}
The GetActiveAmmo() function puts references to all of the active fired ammunition from the weapon
in the input ActiveAmm o array and returns the number of active ammunition. (See Listing 7-27.)
Listing 7-27. Getting All the Active Ammunition
int GetActiveAmmo(int StartIndex, Object3d[] ActiveAmmo)
{
// Put all active fired ammunition in ActiveAmmo array
// and return the number of fired ammunition
int AmmoNumber = StartIndex;
for (int i = 0; i < MAX_DEFAULTAMMO; i++)
{
if (m_WeaponClip[i].IsFired() == true)
{
ActiveAmmo[AmmoNumber] = m_WeaponClip[i];
AmmoNumber++;
}
}
return (AmmoNumber - StartIndex);
}
The Fire() function fires a projectile associated with the weapon in the direction held in the input
parameter Direction and starting at the WeaponPosition position.
The Fire() function (see Listing 7-28) does the following:
1.
Continues if the weapon is ready to fire, based on a minimum time delay value
between firings; otherwise, it returns from the function
2.
Finds a piece of ammunition that has not been fired yet
 
Search WWH ::




Custom Search