XNA Game-Themed CS1 Examples (XGC1)

Release 2.0 (XNA V3.1)
2/8/2010

Topic: Topic.6.Arrays
Example: Ex_3.ExampleWithLoopAndArray

Arrays: Using Arrays (And Loops) To Keep Track of Multiple Objects


References:

Goals:



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:


As you can see, this program draws five soccer balls across the screen.  The program also draws a basketball on the screen, and allows you to move the basketball using the right thumbstick.  You may also move the fifth soccer ball using the left thumbstick.  The major change for the player in this game is that pressing the A button both increments the value stored in element #0 in the array, and also adjusts the size of soccerball #0 to reflect that value.  Similarly, the B button controls the second array element and soccer ball, the X button the third, and the Y button the fourth. 


2. Examining The Program:

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


FURTHER EXERCISES:

  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 refering the tutorial's code.
  2. Adding Circles
    For this exercise, you should use the same project that was explained in the above tutorial, and modify it so that it does the following:
    1. Have the program put 7 soccer balls on the screen. 
    2. The A button should increase the size of the SECOND soccer ball (from the left), the B button should increase the size of the FOURTH, the X button the FIFTH, and the Y button the SIXTH.
    3. The left thumbstick should move the seventh ball around the screen. 
  3. Increasing and Decreasing The Soccer Ball Sizes
    For this exercise, you should use the same project that was explained in the above tutorial, and modify it so that when you push the A button, the radius of all the soccer balls is increased by 1.  When you push the B button, the radius of all the soccer balls should be decreased by 1. 

Project home page: The Game-Themed Introductory Programming Project.
Kelvin Sung
Computing and Software Systems
University of Washington, Bothell
ksung@u.washington.edu
Michael Panitz
Business And Information Technology
Cascadia Community College
mpanitz@cascadia.eduu

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.
2/8/2010