YOUR FEEDBACK
Immo Huneke wrote: A well written article, an ingenious solution to a real problem often encountere...

SYS-CON.TV
TOP MICROSOFT .NET LINKS


XNA or Game Development for Everyone - Part 2
Restructuring the game

In Part 1 of this article, we started to develop a small racing game using XNA Game Studio Express 2.0. We learned about the game loop and how it’s implemented by the XNA (by using the Update and Draw methods) framework. We also created our first track on the screen and four cars started moving on the screen, but, sadly enough, they left the track and weren’t seen again. What does that mean? It means we should take a closer look at collision detection. In addition we should design a menu with different options. You might remember that we want to have a racing game with three computer-driven cars or a network game with one or more other humans playing against us. Sounds easy? Well, it’s not that hard, but we’ll see that a few small changes in the behavior will lead to a few other problems that have to be solved (i.e., a game menu means we have to use so-called game states). Are you ready? Great, let’s go!

Collision Detection
Our cars simply leave the track and disappear from the screen or one car drives through another one, which shouldn’t happen. When the cars leave the track or crash into one another, we need to react within the racing game. This involves two different checks.

Leaving the Track
We definitely need a way to check if our cars are still on track. This can be done easily if we take our track (see Figure 1) and open it with our favorite image processing tool (e.g., .NET Paint or Photoshop). Change the image so it looks like the one in Figure 2. I think you can see the difference. The road – where the cars are allowed to drive – is gray; everything else – where the cars are not allowed to drive – is painted white.

This gives us exactly what we need. We are able to compare the current position of any of our cars against the position in the picture. If the color is gray, everything is fine, and the car is on track. If the current position’s color is white, then the car is leaving the track, which means we will stop the car immediately. What are the black and red lines good for? The black one is the start and finish line so you can count the laps for every single player. The red one determines when the car really finished a lap. You might remember that the XNA framework updates and redraws the scenery several times a second; it wouldn’t be correct if we determined that we are on the black line several times a second and updated the lap counter more than once. The green line is there to prevent cheating. One of the first things we tried in the original game was to cross the start line, turn around, drive back, and turn around again and finally cross the start line again to get another lap counted. This is not supposed to work and is handled by the green line. Only when the green line is crossed can you pass the start line later on and get the lap counted.

About 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 admin@bhitcon.net.

MICROSOFT .NET LATEST STORIES
Midnight Coders has launched WebORB PDF Generator, a solution consisting of a SDK and runtime PDF generation engine that enables Flex, Flash, AJAX and Silverlight clients to create PDF documents from application data. The product is designed for organizations that need to support compl...
At the opening keynote of the Consumer Electronics Show (CES) Wednesday night, Microsoft CEO Steve Ballmer, making his first appearance at the show in a slot that used to be reserved for Bill Gates, announced the widely anticipated, feature-complete beta of the company’s new Windows ...
MYNAH Technologies has announced the release of its MiMiC v3.1.0 Simulation Software for operator training and automation system testing. This release includes enhancements to simulation dynamics, performance and ease-of-use. The new MiMiC Server release provides multi-user support to...
Micro Focus has announced the availability of Micro Focus COBOL for Eclipse, encompassing versions of Micro Focus' Net Express and Server Express solutions designed specifically for the Eclipse open source ecosystem. Micro Focus COBOL for Eclipse provides an integrated development en...
NewerTech has announced the new Voyager Q Hard Drive Docking Solution. The Voyager Q turns any 2.5" or 3.5" Serial ATA (SATA) I/II up to 2.0TB hard drive into a fully bootable and hot-swappable external drive solution and features four interfaces: FireWire® 800, FireWire 400, USB 2.0...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

Click Here

SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE
BREAKING NEWS FROM THE WIRES
Microsoft Dynamics solutions, which serve as essential technology for manufacturers and distributors...