Time for action - drawing the game structure

  1. In the Game1.cs file, replace the current Draw method with the following:
    protected override void Draw(GameTime gameTime)
    {
    GraphicsDevice.Clear(Color.Black);
    spriteBatch.Begin();
    if (gameState == GameStates.TitleScreen)
    {
    spriteBatch.Draw(titleScreen,
    new Rectangle(0, 0, this.Window.ClientBounds.Width,
    this.Window.ClientBounds.Height),
    Color.White);
    }
    if ((gameState == GameStates.Playing) ||
    (gameState == GameStates.PlayerDead) ||
    (gameState == GameStates.GameOver))
    {
    starField.Draw(spriteBatch);
    asteroidManager.Draw(spriteBatch);
    playerManager.Draw(spriteBatch);
    enemyManager.Draw(spriteBatch);
    explosionManager.Draw(spriteBatch);
    spriteBatch.DrawString(
    pericles14,
    "Score: " + playerManager.PlayerScore.ToString(),
    scoreLocation,
    Color.White);
    if (playerManager.LivesRemaining >= 0)
    {
    spriteBatch.DrawString(
    pericles14,
    "Ships Remaining: " +
    playerManager.LivesRemaining.ToString(),
    livesLocation,
    Color.White);
    }
    }
    if ((gameState == GameStates.GameOver))
    {
    spriteBatch.DrawString(
    pericles14,
    "G A M E O V E R !",
    new Vector2(
    this.Window.ClientBounds.Width/2 -
    pericles14.MeasureString ("G A M E O V E R !").X/2,
    50),
    Color.White);
    }
    spriteBatch.End();
    base.Draw(gameTime);
    }
    
  2. Execute the game and play through a complete cycle.

What just happened?

While the whole Draw() method is presented here for clarity, the only major changes are the inclusion of the DrawString() calls to display the player's score and remaining ship count, along with the display of the G A M E O V E R ! text string when in the GameOver state.

Have a go hero -

Here are a few suggestions for putting the topics we have covered in this chapter to use:

  • Currently, Asteroid Belt Assault never gets more difficult as time passes. Add a timing mechanism that increases the number of asteroids, the frequency with which enemy ships are generated, or the rate at which the enemy ships fire at the player, as time goes on.
  • Add new waypoint paths for enemies to follow, or create new enemy types by adding to the SpriteSheet.png file. You could create larger enemies that stay on the screen for a longer period of time, take multiple hits from player weapons, and fire more rapidly at the player.
  • The SoundManager class can be used with very few changes in other games. Try adding it to the Flood Control game and creating your own sound effects for turning pieces, completing a scoring row, and finishing a level.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.4.239