Time for action – interacting with zombies
In the
Update()
method of the LevelManager class, replace theforeach
loop that updates the enemies list entries with the following loop:for (int x = enemies.Count - 1; x >= 0; x--) { enemies[x].Update(gameTime); if (!enemies[x].Dead) { if (player.CollisionRectangle.Intersects( enemies[x].CollisionRectangle)) { if (player.WorldCenter.Y < enemies[x].WorldLocation.Y) { player.Jump(); player.Score += 5; enemies[x].PlayAnimation("die"); enemies[x].Dead = true; ; } else { player.Kill(); } } } else { if (!enemies[x].Enabled) { enemies.RemoveAt(x); } } }
In the Player class, add a declaration to hold the lives the player has remaining:
private int livesRemaining = 3;
Still in the Player class, add a property...