Game Development Reference
In-Depth Information
{
enemy.Health ¼ 0; // kill the enemy off
}
}
}
public void Render(Renderer renderer)
{
_enemies.ForEach(x = > x.Render(renderer));
}
private void RemoveDeadEnemies()
{
for (int i ¼ _enemies.Count - 1; i > = 0; i-)
{
if (_enemies[i].IsDead)
{
_enemies.RemoveAt(i);
}
}
}
}
An extra function needs to be added to the Enemy class to check if the enemy has
been destroyed.
class Enemy : Entity
{
public bool IsDead
{
get { return Health == 0; }
}
The IsDead method of the Enemy class returns true if the enemy's health
is equal to 0; otherwise, it returns false . The EnemyManager , like the
BulletManager , has an out of bounds check, but it's a little different. Enemies
in a scrolling shooter game tend to start off on the far right of the screen and then
move past the player exiting to the left. The out of bounds check compares the
right-most point of the enemy bounding box against the left-most part of the
screen. This removes enemies that the player fails to destroy and that escape off
the left of the screen.
 
Search WWH ::




Custom Search