Upcoming Events
Southwest Gaming Expo
11/20 - 11/22 @ Dallas, TX

Workshop on Network and Systems Support for Games (NetGames 2009)
11/23 - 11/25 @ Paris, France

ICIDS 2009 Interactive Storytelling
12/9 - 12/11 @ Guimarães, Portugal

Global Game Jam
1/29 - 1/31  

More events...


Quick Stats
7498 people currently visiting GDNet.
2341 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!



Link to us

Link to us

  Intel sponsors gamedev.net search:   

Microsoft XNA Game Studio 3.0 Unleashed
Creating a 3D Game


Creating the Tunnel Vision Game

The game is set in outer space. The tunnel to our space station is being attacked, so we need to defend the tunnel and not let our enemies breach the opening. We have missiles that we can fire. Fortunately, the enemies do not have any. They simply attack in swarms, which means we need to take swift action to destroy them.

Creating the Game States

To get started, we need to make a copy of our GameStateDemo from Chapter 17, “Finite State Machines and Game State Management.” We want to use the latest XELibrary from the last chapter, and we need to add the project to our solution because we will be making a modification to it a little later.

Rename Game1.cs to TunnelVision.cs. We can also change the name of this class and the namespace to TunnelVision. Figure 22.1 shows how we can rename our namespace through the IDE. This will modify all our source files for us. We also need to rename our Game1 class to TunnelVision.


FIGURE 22.1 Visual Studio allows renaming the namespace through the IDE.

Adding a Skybox to Our Game

Let’s add a skybox to our world. Find the skybox.tga file and add it to the Skyboxes folder in the Content project. We need to add a skybox content processor to our Content project as well as select SkyboxProcessor as the content processor for the skybox texture. Then we can add the following private member field to our game:
private Skybox skybox;
Next, we can load the skybox in our LoadContent method:
skybox = Content.Load<Skybox>(@”Skyboxes\skybox”);
To finish up our skybox, we only need to draw it. We can add the following statement to the Draw method:
skybox.Draw(Camera.View, Camera.Projection, Matrix.CreateScale(1000));

Compiling the Game

While we are in our Draw method, we can remove the Begin and End methods for SpriteBatch because each game component will need to call its own. We need to leave the base.Draw method, of course.

Let’s add a camera to our game. We are going to change this camera to one that is more suitable for our game, but for now we can just reference the normal Camera class. We need to change our private member field camera to the public member field Camera:

public Camera Camera;
We utilized the camera variable in the constructor (const). The variable will need to be changed from camera to Camera there as well. To get our game to run successfully, we need to modify our game states that utilize the sprite batch to call Begin and End because we removed it from the main TunnelVision game class. Once those methods are modified, we can compile and run our game.

Reproduced from the book Microsoft XNA Game Studio 3.0 Unleashed. Copyright? 2009. Reproduced by permission of Pearson Education, Inc., 800 East 96th Street, Indianapolis, IN 46240. Written permission from Pearson Education, Inc. is required for all other uses



Creating the Game Logic Part 1


Contents
  Creating the Tunnel Vision Game
  Creating the Game Logic Part 1
  Creating the Game Logic Part 2
  Creating the Crosshair & Camera

  Printable version
  Discuss this article