Game Development Reference
In-Depth Information
we need to look at one of the biggest developer features introduced in Windows 8,
and what better time to do so.
Game state and progression
The main thing our game has been lacking so far is an end. The enemies never stop
flying at the player and the player never dies because the only penalty for dying is a
score penalty. To have a high score, we need an end where we can freeze the score
and say the player has earned it. To do this, we need to add in a way to end the
game when the player dies. In the next chapter we'll look at implementing a proper
menu system, but for now we'll focus on adjusting our game so that it ends and dis-
plays a score to the player.
To get started we need to change our game so that it ends at some point. We'll do
this by damaging the player when the enemy collides with the player ship. This has
the added benefit of giving us a flag that indicates if the player is alive and therefore
if the game is running or finished. Thankfully we already have this functionality in the
Ship base class that the Player inherits from, so we can go ahead and use that. We
also need to decide how many enemies can hit the player before the game ends. In
the sample I chose four enemies, and so with a health value of 100 we need to apply
25 damages per collision to make this work. You may want to choose a health value
of 4 and simply deduct one point of damage for each collision as well; it all depends
on your game and how you want to present that to the player. For this sample we'll
stick to the commonly used 100 hit-points value.
Inside the collision detection code between the player and enemies we need to
remove the code that changes the score and replace it with a call to _player-
>Damage(25) , which will handle damaging the player. As it is game over when the
player dies, we need to add a check to the update method, and stop processing
game logic when the _player->GetIsAlive() returns false. To do this, simply
wrap all of the code in Game::Update with that check.
If you run the game now, you should be able to crash into four enemies before
everything abruptly pauses. Now we need to create a game over screen, and get rid
of all of the graphics from our game. To do this we need to make some modifications
to our renderer to allow us to re-add the game graphics at a later stage, as well as
add in some methods to retrieve the sprites from the Ship and Bullet.
Search WWH ::




Custom Search