Game Development Reference
In-Depth Information
Listing 82: A script that handles common functions of all weapons
The first three variables are used to manage ammunition. The difference between
magazineCapacity and magazineSize is that the first one is constant and tells us the
number of maximum bullets in a single magazine. However, magazineSize is variable and
is reduced by ammoPerFiring whenever the weapon is fired. In addition to ammunition
management, we have other variables to manage timing. For example, reloadTime is the
number of seconds needed to reload the weapon when the current magazine becomes
empty. Additionally, fireRate decides how many times the weapon can be fired in one
second. lastFiringTime and reloadProgress are used in together with fireRate and reloadTime
to compute the timing correctly. The third important aspect we need to manage is whether
the weapon is automatic, which means it has the ability to continuously fire bullets while
the trigger is pulled. This property is managed through automatic and triggerPulled flags.
Finally, we have inHand flag, which affects all other functions: if the weapon is not currently
held in hands, it can not be neither fired nor reloaded.
Search WWH ::




Custom Search