The World’s Leading Microsoft .NET Magazine
   
 
timstall

Donate Today!

Search Box

 

Calendar

««May 2008»»
SMTWTFS
     123
45678910
11
12
13
14
15
1617
18192021222324
25262728293031

My Top Tags

                                       

Mailing List

My RSS Feeds








XNA Real-Time-Strategy Game (with source code)

posted Wednesday, 17 October 2007

I mentioned in my last post about XNA that I've created a sample game, complete with full source code.

 

 

You control the green tank by using the mouse. Left moves, right fires. The goal is to push the numbered crates onto the pink "Victory" tiles, and then hit the green semi-circle button. This demonstrates several things:

  • Collisions - this uses a simply polygon collision detection. It also handles heights - a fireball hovers, so it can pass over the water, but the tanks cannot.

  • User input - collecting mouse input (position, left, right buttons)

  • Animation - the water animates

  • Multiple creatures of different sizes. The green bushes (the square things) increase in size as your tank gets closer.

  • Interacting objects - you can push crates, fire at other units, hit the push button, and collect a powerup to increase your firing rate.

  • Messages

  • Opacity

  • A dashboard section on the button for user information

  • The ability to pause the game - which freezes everything (including the game clock).

Note that all the graphics were made with MSPaint.

 

The code is pretty sloppy, as it was just a toy project and my main point was to explore XNA. There's a ton that could be improved about it.

 

Obviously it's just a cute sample. Especially as XNA can handle scrolling, 3D games, and a lot more, this only skims the surface.

 

One point of note is unit-testing. There is a lot of complex code (movement algorithms, models, collisions, interactions, etc...) that should ideally be tested. However Visual C# express doesn't support unit-testing. So, I made the core DLL be referenced in another solution, which can then test it.

 

Next up: re-writing this in Silverlight. I'll go into more of the details there.

tags:    

links: digg this    technorati    




1. Smuth left...
Tuesday, 27 November 2007 7:28 am

the game sucks, this ia coming from a Games Programmer


2. Tim Stall left...
Tuesday, 27 November 2007 9:13 am

A professional would have left constructive feedback with examples. Keep in mind that it's primarily a technical demo for XNA (hence being on a technical blog with source code).


3. Bob Roberts left...
Monday, 17 December 2007 3:23 am

Thanks for the tutorial. I'm just looking to make a simple 2d game and you demonstrated a lot of stuff that's not shown in the basic xna tutorials. Much appreciated. @Smuth: This is intended to be a tutorial/demo not a playable game. Searching out demo source code and compiling it to play a simple 2D game seems overboard. You are obviously just a bitter wanna-be...and a troll.