Game Development Reference
In-Depth Information
The m_WayPoint variable holds the current waypoint.
private Vector3 m_WayPoint = new Vector3(0,0,0);
The m_WayPointRadius variable holds the radius of the waypoint.
private float m_WayPointRadius = 1.0f;
The m_AITank variable holds the tank object that is controlled by the Driver class.
private Tank m_AITank = null;
The Driver constructor (see Listing 8-43) initializes the class object by
Setting the reference to the tank, which is held in m_AITank .
1.
Creating the tank's finite state machine by creating a new FSMDriver object.
2.
Creating the new tank states StateTankSteerWayPoint and
StateTankProcessCommand and adding them to the finite state machine by
calling the AddState() function.
3.
4.
Setting the default state of the finite state machine to the process
command state.
Resetting the finite state machine by calling Reset() .
5.
Listing 8-43. The Driver Constructor
Driver(Tank Vehicle)
{
// Set Vehicle that is to be controlled
m_AITank = Vehicle;
//construct the state machine and add the necessary states
m_FiniteStateMachine = new FSMDriver();
StateTankSteerWayPoint SteerWayPoint =
new StateTankSteerWayPoint(FSM_StatesTank.FSM_STATE_STEER_WAYPOINT, this);
StateTankProcessCommand ProcessCommand =
new StateTankProcessCommand(FSM_StatesTank.FSM_STATE_PROCESS_COMMAND,this);
m_FiniteStateMachine.AddState(SteerWayPoint);
m_FiniteStateMachine.AddState(ProcessCommand);
m_FiniteStateMachine.SetDefaultState(ProcessCommand);
m_FiniteStateMachine.Reset();
}
The SaveDriverState() function saves key class data members from the Driver class. In order to
save space, Listing 8-44 has been abbreviated. Please refer to the Source Code/Download area
located on apress.com for the full version.
 
Search WWH ::




Custom Search