Tuesday, October 16, 2007

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

[This was originally posted at http://timstall.dotnetdevelopersjournal.com/xna_realtimestrategy_game_with_source_code.htm]

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.

No comments:

Post a Comment