Game Development Reference
In-Depth Information
Calls an ammunition's Fire() function and plays any associated sound
effects associated with that ammunition, if that ammunition exists
3.
4.
Calculates the time that the weapon can be fired again and puts this in the
m_TimeReadyToFire variable
5.
Returns true if the weapon could be fired and false otherwise
Listing 7-28. Firing the Weapon
boolean Fire(Vector3 Direction, Vector3 WeaponPosition)
{
boolean WeaponFired = false;
// 0. Test if this weapon is ready to fire
long CurrentTime = System.currentTimeMillis();
if (CurrentTime < m_TimeReadyToFire)
{
return false;
}
// 1. Find Ammo That is not spent
int AmmoSlot = FindReadyAmmo();
// 2. If Ammo Found then Fire Ammunition
if (AmmoSlot >= 0)
{
WeaponFired = true;
m_WeaponClip[AmmoSlot].Fire(Direction,WeaponPosition,
GetObjectPhysics().GetVelocity());
// Play SFX if available
m_WeaponClip[AmmoSlot].PlayFiringSFX();
}
else
{
Log.e("AMMUNITION ", "AMMUNITION NOT FOUND");
WeaponFired = false;
}
// 3. Firing Delay
m_TimeLastFired = System.currentTimeMillis();
m_TimeReadyToFire = m_TimeLastFired + m_FireDelay;
return WeaponFired;
}
The RenderWeapon() function renders all of the weapon's ammunition that has been fired and is
currently active. (See Listing 7-29.)
 
Search WWH ::




Custom Search