Game Development Reference
In-Depth Information
The ResetWeapon() function resets all of the weapon's ammunition. (See Listing 7-23.)
Listing 7-23. Resetting the Weapon
void ResetWeapon()
{
// Reset All the Ammunition in the Weapon's Magazine
for (int i = 0; i < MAX_DEFAULTAMMO; i++)
{
m_WeaponClip[i].Reset();
}
}
The LoadAmmunition() function puts the Ammunition Ammo in the slot AmmoSlot in the
m_WeaponClip array . (See Listing 7-24.)
Listing 7-24. Loading the Ammunition into the Weapon
void LoadAmmunition(Ammunition Ammo, int AmmoSlot)
{
if (AmmoSlot >= MAX_DEFAULTAMMO)
{
AmmoSlot = MAX_DEFAULTAMMO - 1;
}
m_WeaponClip[AmmoSlot] = Ammo;
}
The FindReadyAmmo() function returns the index number of the first available piece of ammunition
available for firing or -1, if there is no available ammunition. (See Listing 7-25.)
Listing 7-25. Finding Spare Ammunition
int FindReadyAmmo()
{
for (int i = 0; i < MAX_DEFAULTAMMO; i++)
{
// If Ammo is not Fired
if (m_WeaponClip[i].IsFired() == false)
{
return i;
}
}
return -1; // No More Ammo Available
}
The CheckAmmoCollision() function tests if the input object obj is colliding with any of the weapon's
fired ammunition. It returns a reference to the object if there is a collision or null if there is no
collision. (See Listing 7-26.)
 
Search WWH ::




Custom Search