XNA Game-Themed CS1 Examples (XGC1)

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

Topic: Topic.5.RepetitionStructures
Example: Ex_4.SinePlotWithWhile

Animating Sinusoidal Motion


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:


This program is extremely similar to the program featured in the previous tutorial - the only visible difference is that there's now a small basketball moving along the path that has been plotted out by the soccer balls.   Internally, we've also set up a couple of new functions to make our programming easier.

Note that while this tutorial does demonstrate a very cool, and very useful game-programming technique, it doesn't do anything new with loops.


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. Improving The Game: Changing the speed of the moving basketball
    For this exercise, you should use the same project that was explained in the above tutorial.
    Modify the provided program, so that when the user presses the X button, the small basketball moves faster, and when the user presses the Y button, the basketball moves slower.
    Hint: You may find it useful to use the GamePad.ButtonXClicked() and GamePad.ButtonYClicked() functions.
  3. Improving The Game: Graphing Two Functions Simultaneously
    For this exercise, you should use the same project that was explained in the above tutorial.
    Modify the provided program, so that the program does two things, at the same time:
    1. Draw a sine wave with small soccer balls, and moves a small basketball along it.  (This is what the provided program already does)
    2. Draw a cosine wave with small basketballs, and moves a small soccerball along it.  (You will need to add this part)

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