XNA Game-Themed CS1 Examples (XGC1)

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

Topic: Topic.4.DecisionStructures
Example: Ex_3.IfWithFunction

Decision Statements: "If" Statements and Functions


Need (library reference):

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:


The game behaves in a manner that is identical to the what was described for the previous tutorial, with two new changes:

  1. If the soccer ball reaches the left edge of the screen, it will 'bounce off' that edge, meaning that it will reverse it's horizontal direction. 

  2. If the soccer ball collides with the right paddle, it will 'bounce off' that paddle, meaning that it will reverse it's horizontal direction.  We will also play a sound, in order to provide audio feedback to the user that the player has successfully bounced the ball


2. Examining The Program:

Let's examine the C# source code that produces the behavior we see on-screen.  Since the code is nearly identical to the program that was presented in the previous tutorial, we'll leave out everything, except for code that has changed, or code that is new.  That leaves us with:


FURTHER EXERCISES:: 


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