Game Engine Tutorial Part II – Setting Up the Project

First things first, you need Microsoft Visual C# Express Edition and Microsoft XNA Game Studio installed on your computer. If you don’t, follow Microsoft’s XNA Quick Start Guide.

Final Project Tree

Final Project Tree

Once you have installed everything, go ahead and launch Visual C# Express. The first thing we must do with any project is create the “Solution” file, which is basically just the project file that keeps track of how our project is set up and links all the individual files together. Go to the File menu, and select “New Project”. On the left, select the XNA Game Studio tab, and on the right, select the “Windows Game Library” option. In the “Name” text box, give your project a name. I chose “Innovation Engine” because this is the Innovative Games Game Engine Tutorial, but you can name it whatever you want. Once you’re done, hit “OK” and let Visual Studio create the project.

What we’ve just done is created a solution file, which has one “Project” file in it. Each project represents something that will be built by C#, either a “Library”, which is basically a file that other projects can reference to get access to code stored inside, or an “Executable”, which is the file that Windows can actually run as a program. In this case, we’ve created a library. Inside this library we will place all the code and classes relating to the engine itself. In a moment we will add another project that will build into the executable: the game itself. In that project we will place all the code that relates to our game itself. The reason for this is to maintain a separation between the “Engine” code and the “Game” code, as doing so will allow the engine code to be reused on other games.

Right now we are going to add another project that will represent our demo game. We will use this game to test features we add to the engine. Open the “Solution Explorer” tab on the side of the screen. If you can’t see it click on it under the View menu. Right click on the “Solution” node in the solution tree. It will say “Solution” and the name you gave your engine in quotes, ie: “Solution ‘InnovationEngine’ (1 Project)”. In the popup menu, under “Add”, click “New Project…”. This time, select “Windows Game” on the right side of the project wizard, and give this one a name. For example, I named mine “InnovationEngine Demo Game”.

Next, we need to link the engine’s library to the game’s executable, so that we can actually access the code stored in the library. To do this, go to the solution explorer again, and under the game’s node (ie “InnovationEngine Demo Game”), right click on the “References” node, and click “Add Reference”. In the dialog that will pop up, click on the “Projects” tab, and select your engine’s library (ie “InnovationEngine” – it should be the only one in the list anyway). Hit OK, and Visual Studio will link the projects.

Our projects are now setup, but we need to do a little cleanup of the default code that has been generated for us. Open up the “Game1.cs” file under the game’s node. We will simplify the code here by removing all the extraneous comments and some unnecessary functions.

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace InnovationEngine_Demo_Game
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
        }

        protected override void LoadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            base.Draw(gameTime);
        }
    }
}

The class that we are working on right now is the link between our game and XNA. You will note by the class declaration: “public class Game1 : Microsoft.Xna.Framework.Game” that we are inheriting from the “Game” class, which is provided by XNA. It has predefined functions for Updating, Drawing, and Loading the game. It also provides references to some core parts of the framework, like the graphics device for working with the graphics card, and the Input class for getting input from the controllers and keyboard/mouse. XNA will load our game, then call those functions when it needs us to update or draw the game, so all we have to worry about is writing the code to draw what we want and have the game do the things we want in those functions.

There is actually one more thing we need to do to link the engine to the game, and that is to add another “using” statement, to let the compiler know that we will be referencing code from the library in the Game class. Look at the top of the “Game1.cs” file, and you will see that there are already a number of “using” statements already there, to core system libraries and some of the XNA libraries. We will add one more to the list.

using InnovationEngine;

Now we will build the project for the first time. By default, Visual Studio will try to launch the first project we added to the solution. However, as that project is a class library, it cannot be run like a program. We need to let Visual Studio know that it should launch the game project, not the library project. Right click on the game project’s node in the solution explorer (labeled “InnovationEngine Demo Game” in my case) and click “Set as StartUp Project”. At this point, if you press F5 to build and run the game, you should see your empty game window pop up with a blank blue screen.

Running Game

Running Game

This is probably a good time to save everything. Press “Ctrl+Shift+S” to save all your files, or click “Save All” in the File menu.

In the next chapter we will discuss the engine’s design then start on building it!

Download the Code for this Chapter

5 Responses to “Game Engine Tutorial Part II – Setting Up the Project” »

  1. Pingback by Innovation Engine Roadmap 2009-2010 | Innovative Games — October 19, 2009 @ 5:11 pm

    [...] Game Engine Tutorial Part II – Setting Up the Project [...]

  2. Comment by Eibach06 — October 19, 2009 @ 5:33 pm

    great work =)

  3. Comment by Will — October 19, 2009 @ 6:03 pm

    Great stuff, vant wait for the next one!

  4. Pingback by TTengine tutorial part 2: it’s all about Properties — May 30, 2011 @ 11:10 pm

    [...] after the next few posts or so). For starters, the other tutorial (the nice one) will show you even how to setup your game project in Visual studio. Wow, that’s great – I’m too impatient right now to tackle that. There’s a [...]

  5. Comment by % — December 17, 2011 @ 4:36 am

    My partner and i haven’t listened nevertheless, nevertheless would these people really move the experience right outside the entrance? seemed to be this specific purposely or unintentional?

RSS feed for comments on this post. TrackBack URI

Leave a comment