PowerBuilder Tips, Tricks, and Techniques

Berndt Hamboeck

Subscribe to Berndt Hamboeck: eMailAlertsEmail Alerts
Get Berndt Hamboeck: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

Related Topics: Artificial Intelligence Journal, Game Developer

Artificial Intelligence: Article

XNA, Game Development for Everyone

Writing games sure isn't what it used to be

What Is XNA Game Studio
Microsoft defines XNA as everything a game developer needs to build industry-leading software, including the services, resources, and communities, to be successful on Microsoft gaming platforms (the PC world and, in my opinion, the best next-generation console - the Xbox 360). XNA Game Studio is only a subset of this whole industry (just have a look at the Xbox 360 marketplace or your Xbox Live gamer score to get a picture of what the other parts are), but for a developer the most exciting part is the API to write games. Using it we have easy access to input devices like the game pad (on a PC keyboard and mouse), the graphics hardware and audio and since XNA Game Studio 2.0 networking through the Xbox Live technology.

Xbox 360 or PC Game?
XNA lets us write games for the Xbox 360, but an Xbox 360 isn't needed to use XNA. We can write games strictly for the PC. However, if we want to write games we can play on our Xbox 360 and have others play the game we wrote on their consoles, we need to buy an XNA Creators Club subscription. This will let us play other community games (that other developers create) on our Xbox 360 and get additional content from the XNA development team.

Getting Started
The hardware and software requirements are easy:

  • Any PC with Windows XP or Vista installed.
  • Microsoft XNA Game Studio Express - a free download.
  • Any version of Visual Studio 2005 (including the free Visual C# 2005 Express Edition) - Visual Studio 2008 isn't supported today.
  • Some (at least basic) C# knowledge and understanding of the Microsoft .NET Framework, since that is what the XNA Framework runs on. Currently games on the XNA framework can only be written using the C# programming language
  • An Xbox 360 console (the hard drive must be connected to the console) - if you want to try your games on something other than a PC.

Our First Game
When we want to create a new game in XNA we have two options. Either we use one of the available starter kits that help get everyone started by seeing a working game in action directly from inside Visual Studio (see Table 1, but note that not all of them come with XNA, so look at the XNA Creators Club web site - see Error! Reference source not found. section below). Otherwise we have to start a completely new project on our own (which is exactly what we want to do here). The reason is that the available starter kits are quite complex and might not show you how easy it is to build a simple game using XNA. When I say simple we should talk about what I'd like to build. I'll tell you about a dream I've had for a long time.

The Dream
When I worked as a consultant for a big phone company in Germany we sometimes (only during lunch break of course) played a free game called VW Lupo Cup. This game is a fantastic, though quite simple, racing game. Up to four players can drive small cars around a few different tracks. The really cool thing was that we could play at the same time using the network - it's so much fun, you should really give it a try sometime. But after a while the levels got boring and there was no level editor or source code available. I've wanted to build this game on my own now for quite a while (meantime I've had two wonderful little girls). Now, with the release of XNA Game Studio 2.0 and its new multiplayer features, my dream should become reality and I think you should share my dream and that we should build the game together. If you look at Figure 1 you'll get a sense of how the game should look. Let's sum up some of the must-have features I'd like to see in the game:

  • A nice racing circuit that our cars drive around.
  • Four cars (or players) driving at the same time.
  • The cars should react when we press the keyboard or use the Xbox controller.

Then there are the features that we need to implement, but won't fit in this month's article:

  • The cars can't leave the track.
  • They have to react when they collide.
  • Different circuits with different difficulties.
  • Count the laps and lap time of each player.
  • Different game states (start screen, race, end of race, configuration)
  • Multiplayer over a LAN
  • Realistic velocity handling (gears, brakes)
  • If there are no people available to play, the computer should drive a car (AI)
  • If a player leaves the track the car and lands in the grass the car only slows down
  • Damage-handling and repair system
  • After the race a car can be fixed.
  • As you can see a computer game (even a simple racing game) never seems to be finished, but before we can think about finishing it we should start implementing the basic features.

    Implementing XNA Car CUP
    So let's fire up Visual Studio 2005 and create a new project by choosing Visual C# - XNA Game Studio 2.0 and Windows Game - see Figure 2.

    OK, fine, we have a new project, but we actually have more than that, since the XNA development team has already done a lot of the hard work for us by creating some important functions waiting for us to be coded:

    • The Initialize method is where we can initialize whatever needs to be initialized, but doesn't have anything to do with the actual content.
    • The LoadContent method is where we load all the cool stuff such as models and textures that make our games look good.
    • The UnloadContent method is where any game assets can be released. Usually we don't have to code anything here, since the assets will be released automatically when they're no longer needed.
    • The Update Loop - A game loop is a loop that's definitely needed in game development since objects have to be updated regularly (our cars should move forward) and process other elements such as keyboard or joystick input, sound, artificial intelligence, and physics. So the Update method is the best place to update the game logic we're going to implement to move our cars around, react to the player input, and resolve collisions between cars.
    • The Draw Loop is the place where our game background and cars are rendered on the screen. Each iteration of the rendering and Draw Loop (the update and the Draw methods) is called a frame. These functions are the most critical in a game, and the more computations in our game logic and the more objects we draw on the screen the slower our game can get (which means that most optimizations in game development are done in these two functions).

    More Stories By Berndt Hamboeck

    Berndt Hamboeck is a senior consultant for BHITCON (www.bhitcon.net). He's a CSI, SCAPC8, EASAC, SCJP2, and started his Sybase development using PB5. You can reach him under [email protected]

    Comments (4)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.