XNA Game-Themed CS1 Examples (XGC1)

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

Topic: Topic.3.ModulesAndFunctions
Example: Ex_1.SimpleFunctionCall

Simple Function Call



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:


As you can see, there is a single soccer ball on the screen.  Using the right thumbstick, you can move the soccer ball around (if you want, you can even move it off the screen).  The program prints out a simple, purely textual message at the top of the screen, and it prints the current location of the soccer ball at the bottom of the screen.

The game will exit if you press the 'Back' button, as is true for all the tutorials so far.  Because this is a standard feature of our programs, it will not be mentioned in future tutorials.


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. For this exercise, you should use the same project that was explained in the above tutorial.
    Create a new function, named EchoMessageToBottomStatus.  It should print out the words "Hello, Everyone!" to the bottom of the screen.  Make sure that you call this function from the UpdateWorld method.
  3. For this exercise, you should use the same project that was explained in the above tutorial.
    Create a new function, named EchoMessageToBottomStatus2.  It should print out the words "Soccer Ball Position: ", followed by the current center of the soccer ball, to the bottom of the screen (just like you see in the provided starter project).  Make sure that you call this function from the UpdateWorld method.

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