Game Programming OO Overview
24 Feb 2009

Game Programming is an Object Oriented enterprise. When we use XNA2/C#, we have managed code development facilitated by the C# environment using the XNA framework. When you select New project from the Xna Game Studio 2.0 / C# 2005 Express start menu, the skeleton file code is created for you.

Our textbook, Beginning XNA 2.0 Game Programming: From Notice to Professional Apress tries to provide a broad look at the development of a 2d or a 3d game. This is a lot to cover and we hope this page will provide a big picture view.

Below, we briefly focus on the portions of this file. For clarity, all comments have beenr removed.


Lots of using declarations were here
namespace Stewart_Game1
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
            base.Draw(gameTime);
        }
    }
}
Object Oriented Programming - implies you must design your game to engage the user
We have discussed game design using the resource from Chris Crawford 27Jan Lecture

Use a scene graph to organize the interations between objects in your game
The Scene graph (wiki) provides an appropriate data structure to visualize the objects in a computer game so that the object properties are clear and the the programmer can anticipate the interactions of the various objects that will be placed in the game.

When you design your game, you choose to have objects that will interact with the player and defines the activity of the game. For the 2d game, you created a sprite and set up its properties. In Chapter 3, you created the GameComponent for the 2d game Rock Rain. The player is represented as a space ship and the meteors are the objects the player interacts with. Each of the objects will be created by XNA/C# as a Game Component, your game assets with their own properties.

p. 15 Summary give a nice big-picture view and its roughly reproduced here.

The Game Structure:

Intiialize graphics, input and sound
Load resources
Start game loop.  In every step:
	Gather user input
	Perform needed calculations (AI, movement, collision detection, etc.)
	Text for game ending criteria - if met, stop looping
	Draw (render) screen, generate sounds and game controller feedback
Finalize graphics, input and sound
Free resources

This general game structure maps onto the 
XNA Game class overridable methods:

Game1() - General initialization
Initialize() - Include nongraphics initialtion 
LoadContent() - Include graphics initialization 
Run() - Start game loop.  In every step:
	Update() - Include code to read and process user input, do 
		calculations for AI, movements and collisions, and test 
		for game end
	Draw() - Include the drawing (renderization) code
UnloadContent() - Free graphics resources


Another useful text is XNA 2.0 Game Programming Recipes, by Riember Grottjans, Apress. The author provides his own gateway to tutorials on XNA www.riemers.net which you may find useful.

Riemers characterizes the XNA Framework as divided into 3 parts.

  1. the XNA project (the C# code you write)
  2. the content pipeline (or Fig 1-3 from our text)
  3. HLSL effects (to improve visual quality of final image) Ch 8 our text High Level Shader Language (wiki)