Game Development Reference
In-Depth Information
Listing 10-29. Adding a New Tank to the Playfield
boolean AddNewTank()
{
boolean result = false;
Tank TankVehicle = m_TankFleet.GetAvailableTank();
if (TankVehicle != null)
{
TankVehicle.Reset();
TankVehicle.GetMainBody().GetObjectStats().SetHealth(100);
// Set Position
Vector3 Max = new Vector3(m_Grid.GetXMaxBoundary(), DROP_HEIGHT, -5.0f);
Vector3 Min = new Vector3(m_Grid.GetXMinBoundary(), DROP_HEIGHT, m_Grid.
GetZMinBoundary());
Vector3 Position = GenerateGridLocationRestricted(Max, Min);
TankVehicle.GetMainBody().m_Orientation.GetPosition().Set( Position.x,
Position.y, Position.z);
// Set Command
SetTankOrder(TankVehicle);
result = true;
}
return result;
}
The UpdateArenaObjects() function adds more arena objects to the playfield, if needed.
(See Listing 10-30.)
The UpdateArenaObjects() function does the following:
1.
If there are fewer arena objects on the playfield than the minimum number, it
creates a new arena object by calling AddNewArenaObject() .
2.
If there are enough arena objects on the playfield, it checks to see if
the elapsed time since adding the last arena object is greater or equal
to m_TimeDeltaAddArenaObject . If it is, it adds another object by calling
AddNewArenaObject() .
Listing 10-30. Updating the Arena Objects
void UpdateArenaObjects(long CurrentTime)
{
// Check to see if need to add in more Arena Objects
int NumberObjects = m_ArenaObjectsSet.NumberActiveArenaObjects();
if (NumberObjects < m_MinArenaObjectsOnPlayField)
{
// Add another object to meet minimum
boolean result = AddNewArenaObject();
 
Search WWH ::




Custom Search