Game Development Reference
In-Depth Information
if (definition.EnemyType == "cannon_fodder")
{
// The enemy type could be used to alter the health or texture
// but we're using the default texture and health for the cannon
fodder type
}
else
{
System.Diagnostics.Debug.Assert(false, "Unknown enemy type.");
}
return enemy;
}
public void Update(double elapsedTime, double gameTime)
{
UpdateEnemySpawns(gameTime);
The Update methods in the EnemyManager and Level class have been
modified to take in a gameTime parameter. The gameTime is a number that
counts down to zero, at which point the level will end. This value is used to
determine when to create new enemies. The InnerGameState has to pass this
gameTime value into the Update method of the Level object, and the Level
passes it on to the EnemyManager .
// In Level.cs
public void Update(double elapsedTime, double gameTime)
{
_enemyManager.Update(elapsedTime, gameTime);
// In InnerGameState.cs
public void Update(double elapsedTime)
{
_level.Update(elapsedTime, _gameTime);
The gameTime is passed all the way from the inner game state down to the
UpdateEnemySpawns function in the EnemyManager . UpdateEnemy-
Spawns first checks if there are any upcoming enemies in the _upcomin-
gEnemies list; if there aren't, then the method does nothing. If there are some
upcoming enemies, the code checks the top of the list to see if it's ready to be
launched. If the enemy definition is ready to be launched, then it's removed from
the _upcomingEnemies list and the definition is used to make a new enemy
 
Search WWH ::




Custom Search