XNA Game-Themed CS1 Examples (XGC1)

Release 2.0 (XNA V3.1)

Topic: Topic.6.Arrays
Example: Ex_10.PongWithStat

Pong Soccer: Now With Statistics!!



1. Obtain the example code

Download and unzip the zip file and you will see an ExampleProgram folder. Open the ExampleProgram folder, the EXE folder contains the compiled program and you can double click on the .sln file to work with the source code.

When the game starts, you'll see a screen that looks similar to this:

This program is built off the Soccer Pong game that you have seen previously.  The new features for this tutorial are:

  1. The player can pause the game by pressing the 'Start' button (which is mapped to the W key, on the keyboard)
  2. The player can start the game over by pressing the 'A' button.
  3. InitializeBlocks: new function to create and initialize the blocks.
  4. The stats about the game are being echoed to the top status bar, using the functions we saw in the previous tutorial
  5. The declarations of several of the named constant have been changed, so that it will be easier to add new blocks to the game

Let's examine these new features, one by one:

2. Examining The Program: Pausing the Game

When the player presses the 'Start' button ('W' on the keyboard), the game will pause.  What this means that during each call to UpdateWorld, no work will be done.  The soccer ball will not be moved, the paddles will not be moved - nothing.  The only thing that will be done is to check and see if the player wants to exit the game, or if the player has decided to unpause the game.

3. Examining The Program: InitializeBlocks and restarting the game.

 Let's examine the C# source code that produces the restarting behavior we see on-screen:

4. Examining The Program: Collecting Statistics And Displaying Them

 Let's examine the C# source code that produces the restarting behavior we see on-screen:

5. Examining The Program: Making It Easier To Add Bricks

 Let's examine the C# source code that produces the restarting behavior we see on-screen:


  1. Start from a blank starter project (1000.201, if you need it), and re-do the code from memory as much as possible.  On your first try, do what you can, and keep the above code open so that when you get stuck, you can quickly look up what you forgot (and that after you finish a line, so that you can compare your line to the 'correct' line).  On the next try, do the same thing, but try to use the finished code less.  Repeat this until you can type everything, without referring to the tutorial's code.
  2. Examining The InitializeBlocks() Function
    For this exercise, you should use the same project that was explained in the above tutorial.
    What happens if you remove the the line that calls RemoveFromDrawSet on the current blocks?  Which blocks does the soccer ball collide with?  Why?

Project home page: The Game-Themed Introductory Programming Project.
Kelvin Sung
Computing and Software Systems
University of Washington, Bothell
Michael Panitz
Business And Information Technology
Cascadia Community College

Microsoft Logo This work is supported in part by a grant from Microsoft Research under the Computer Gaming Curriculum in Computer Science RFP, Award Number 15871 and 16531.