Game Development Reference
In-Depth Information
Listing 8-44. Saving the Driver
void SaveDriverState(String Handle)
{
SharedPreferences settings = m_AITank.GetMainBody().GetContext().getSharedPreferences(Handle, 0);
SharedPreferences.Editor editor = settings.edit();
// Turn Area
String TurnAreaKey = Handle + "TurnArea";
editor.putFloat(TurnAreaKey, m_TurnArea);
.. Rest of code
}
The LoadDriverState() function loads key data for the Driver class. The code in Listing 8-45 has
been abbreviated. For the full code, please see the Source Code/Download arealocated on
apress.com .
Listing 8-45. Loading the Driver State
void LoadDriverState(String Handle)
{
SharedPreferences settings =
m_AITank.GetMainBody().GetContext().getSharedPreferences(Handle, 0);
// Turn Area
String TurnAreaKey = Handle + "TurnArea";
m_TurnArea = settings.getFloat(TurnAreaKey, 4.0f);
.. Rest of code
}
The IncrementNextWayPoint() function sets m_WayPoint to the next waypoint for the tank, if the
current command is the Patrol command. (See Listing 8-46.)
Listing 8-46. Finding the Next Waypoint
void IncrementNextWayPoint()
{
AIVehicleCommand Command = m_CurrentOrder.GetCommand();
if (Command == AIVehicleCommand.Patrol)
{
m_CurrentOrder.IncrementWayPointIndex();
m_WayPoint = m_CurrentOrder.GetCurrentWayPoint();
}
}
The SetOrder() function saves the current command in the m_LastOrder variable and sets the
current order to the vehicle Command input parameter. If the command is the Patrol command, the
current waypoint variable m_WayPoint is set to the first waypoint. (See Listing 8-47.)
 
Search WWH ::




Custom Search