Game Development Reference
In-Depth Information
Listing 8-17. Loading a Vehicle Command
void LoadState(String Handle)
{
SharedPreferences settings = m_Context.getSharedPreferences(Handle, 0);
// Command
String CommandHandle = Handle + "Command";
String CommandStr = settings.getString(CommandHandle, "None");
m_Command = MatchCommand(CommandStr);
// Rest of Code
....
}
The
IncrementWayPointIndex()
function increments the
m_CurrentWayPointIndex
variable, which
holds the index of the current waypoint that the vehicle is moving toward. If the last point in the
set of waypoints has already been reached, then the next waypoint is the starting waypoint.
(See Listing 8-18.)
Listing 8-18. Incrementing the WayPoint Index
void IncrementWayPointIndex()
{
int NextWayPointIndex = m_CurrentWayPointIndex + 1;
if (NextWayPointIndex < m_NumberWayPoints)
{
m_CurrentWayPointIndex = NextWayPointIndex;
}
else
{
// Loop Waypoints
m_CurrentWayPointIndex = 0;
}
}
The
ClearCommand()
function clears the vehicle command and the
m_ObjectsAffected
variable to
None. (See Listing 8-19.)
Listing 8-19. Clearing the Vehicle Command
void ClearCommand()
{
m_Command = AIVehicleCommand.None;
m_ObjectsAffected = AIVehicleObjectsAffected.None;
}