Time for action – adding variables to the class declaration area

  1. Right below the SpriteBatch spriteBatch; line, add the following:
    Random rand = new Random();
    Texture2D squareTexture;
    Rectangle currentSquare;
    int playerScore = 0;
    float timeRemaining = 0.0f;
    const float TimePerSquare = 0.75f;
    Color[] colors = new Color[3] { Color.Red, Color.Green, Color.Blue };

What just happened?

These are all the variables you will need for the SquareChase mini game. Here is a quick breakdown:

rand : This instance of the Random class is used to generate random numbers via the Next() method. You will use this to generate random coordinates for the squares that will be drawn to the screen.

squareTexture : The Texture2D class holds a two dimensional image. We will ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.