Game Development Reference
In-Depth Information
_system.ChangeState("game_over");
}
if (_level.HasPlayerDied())
{
OnGameStart();
_gameData.JustWon ¼ false;
_system.ChangeState("game_over");
}
}
Here the Level class has been given an extra function, HasPlayerDied , that
reports if the player has died. In this case, the player's death is checked after the
gameTime . This means that if the time runs out, but the player died in the last
possible second, he still won't win the level.
In the level class, the HasPlayerDied method needs to be implemented. It's
just a simple wrapper around the current PlayerCharacter 's state.
public bool HasPlayerDied()
{
return _playerCharacter.IsDead;
}
The death flag is contained in the PlayerCharacter class.
bool _dead ¼ false;
public bool IsDead
{
get
{
return _dead;
}
}
When the player collides with an enemy, this death flag can be set and the game
will end with the player losing the level. The level needs some code to process the
collisions that happen between the enemy craft and the player. This collision
processing is done in the level class, which has access to the PlayerChar-
acter and the list of enemies.
private void UpdateCollisions
()
 
Search WWH ::




Custom Search