XNA Game-Themed CS1 Examples (XGC1)

Release 2.0 (XNA V3.1)

Topic: Topic.1.GTC_Program_Model
Example: Ex_1.WithXNACS1Lib_FromScratch

Creating Game-Themed Applications from scratch


There a number of things that you need to do, and while each one involves several detailed steps, they basically amount to:


Notice:  To work with the XNACS1Lib  Library, a bare minimum project must include:

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.

2. Create the blank, basic XNA project: 

First, you should create a blank XNA project, without any of the extra 'XNACS1Lib' stuff that you'll be using during this term.  You can do that using the FileNew Project menu option, as pictured below:


Next, you'll need to fill in the details for your new project. Depending on the version of Visual Studio that you're using, your window may or may not look exactly like what's pictured below, but it should appear to be similar to what is pictured below:

  1. In the top-left pane, entitled "Project Types", it may help to select 'XNA Game Studio 2.0', as it will remove options that you don't need from the right-hand pane.
  2. In the top-right-hand pane, entitled 'Templates', you should select the 'Windows Game'. 
  3. Working our way down, you should pick a 'Name' for your project - it's a good idea to include information about what you're working on in the name.  For example, if this is the first assignment that you're doing in this class, you might name it something like Assign_1. 
  4. Next, pick a 'Location' for the project to be stored.  Again, it's a good idea to keep all of your work for this class in one folder, and if there are multiple types of work (for example, put smaller, weekly work underneath one subfolder, and homework projects into a different subfolder)
  5. Unless your instructor specifically tells you otherwise, make sure that the 'Create directory for solution' IS checked.  If you create a project with this checked, then the Solution file (the file with the extension .SLN) will go into a new folder, and all the other files will go into a subfolder beneath that new folder.  This will be nice for you because the next time that you sit down to work on your game, you can just double-click on the .SLN file, which will be easy to find, since it's the only file in that new directory you created.
  6. Finally, click the 'OK' button to go on.



At this point, you've created a basic, XNA video game.  Since you haven't actually added anything to the game, nothing really happens quite yet.  However, we should be able to see the game compile and run just, without crashing, if we've done everything right.  You can run the program (the video game) a couple of different ways.  Using menu options, you should choose the DebugStart Debugging option (you can probably get away with using the Debug →Start Without Debugging option for now, but as you do more programming, you'll want to get familiar with the debugger, so get used to using the 'Start Debugging' option).  Another option would be to use the 'F5' keyboard shortcut, which does the same thing.  Here's a picture:


Once you've done that, you should see a blank screen.  Again, the program is doing exactly what you've told it to do: nothing.


At this point, we've created a basic, normal XNA project; let's add in the dynamic link library that contains the custom game logic that we'll use in our games.

3. Add a reference to the custom XNACS1Lib_PC.DLL library: 


4. Including the font file: 

5. Change the source code to build on the custom logic from the library: 


At this point, you should open up the Game1.cs file, using the Solution Explorer, and examine the source code (if you haven't already).  Firstly, you'll notice that the basic XNA source code that worked immediately after creating the project continues to work just fine now.  That's because the custom logic in the XNACS1Lib_PC.dll builds on the excellent XNA framework that Microsoft has created, instead of replacing it.  However, we want to use the XNACS1Lib logic, since it will provide an easier set of functions and objects to use.  In order to do this, we need to do 2 things:

6. Exercises:

  1. Remove the .DLL file from the finished program, and try to compile and run the game.  What errors do you get?  Make sure that you carefully inspect these errors, so that if you ever accidentally remove the .DLL (or are given a project without the DLL), you will be able to identify the cause of the error.  You don't need to memorize the exact error message, but you should be able to recognize it.  Once you've done this, add the DLL to the game again.

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.