Game Development Reference
In-Depth Information
The
m_NumberRoundsFired
variable keeps track of the number of rounds of ammunition fired for
each burst.
private int m_NumberRoundsFired = 0;
The
m_TimeIntervalBetweenFiring
variable sets the time interval between successive bursts of the
tank's weapon.
private long m_TimeIntervalBetweenFiring = 0;
The
m_StartTimeFiring
variable holds the last time that the tank has fired its weapon.
private long m_StartTimeFiring = 0;
The
m_FireWeapon
variable holds true if the tank's weapon should be fired and false otherwise.
private boolean m_FireWeapon = false;
The constructor for the StateTankSteerWayPoint class calls the constructor for the StateTank
superclass with the
FSM_StatesTank
id, which identifies which state this is to the finite state machine
and the Driver parent object that contains information about this vehicle's commands and the tank
object. (See Listing 8-29.)
Listing 8-29. The Constructor
StateTankSteerWayPoint(FSM_StatesTank ID, Driver Parent)
{
super(ID, Parent);
}
The
Enter()
function is called when this state is first entered by the finite state machine. The function
initializes key variables. Some data is from the parent Driver class object, such as the current
waypoint, waypoint radius, or data from the vehicle command. The
Enter()
function also lets the
parent Driver class object know that the currently executing command is the patrol/attack command.
(See Listing 8-30.)
Listing 8-30. Entering the State for the First Time
void Enter()
{
// Weapon is not firing when state is entered initially
m_NumberRoundsFired = 0;
m_FireWeapon = false;
// Get WayPoint Data
m_WayPoint = GetParent().GetWayPoint();
m_WayPointRadius = GetParent().GetWayPointRadius();
// Get Targeting and firing parameters
m_Target = GetParent().GetCurrentOrder().GetTarget();
m_TargetObj = GetParent().GetCurrentOrder().GetTargetObject();