Game Development Reference
In-Depth Information
if (result == true)
{
m_TimeLastArenaObjectAdded = System.currentTimeMillis();
}
}
else
{
// Check to see if enough time has elapsed to add in another object.
long ElapsedTime = CurrentTime - m_TimeLastArenaObjectAdded;
if (ElapsedTime >= m_TimeDeltaAddArenaObject)
{
// Add New Arena Object
boolean result = AddNewArenaObject();
if (result == true)
{
m_TimeLastArenaObjectAdded = System.currentTimeMillis();
}
}
}
}
The UpdateTanks() function adds a new tank to the playfield by calling AddNewTank() if the current
number of tanks is less than m_MaxTanksOnPlayField and the elapsed time since the last tank was
added is greater than m_TimeDeltaAddTank . (See Listing 10-31.)
Listing 10-31. Updating the Tanks
void UpdateTanks(long CurrentTime)
{
int NumberTanks = m_TankFleet.NumberActiveVehicles();
long ElapsedTime = CurrentTime - m_TimeLastTankOnGrid;
if ((NumberTanks < m_MaxTanksOnPlayField)&&
(ElapsedTime > m_TimeDeltaAddTank))
{
// Add New Tank
boolean result = AddNewTank();
if (result == true)
{
m_TimeLastTankOnGrid = System.currentTimeMillis();
}
}
}
The UpdateController() function updates the number of arena objects on the playfield, if needed,
by calling UpdateArenaObjects() , and updates the number of tank objects on the playfield, if
needed, by calling UpdateTanks() . (See Listing 10-32.)
Search WWH ::




Custom Search