View All Articles or articles on Technology

XNA Challenge (Tower Defense) - Nights 2+3

Another quick update! My time's been fairly limited over the past couple of evenings so not much game wise has got done.

However on the plus side I've got quite a lot done on the name, base story / setting, fast-rendering and cross-platform work.

Name: TowerZ

TowerZ Logo 

Base Story / Setting:
As you may guess from the "logo", it's not a medieval / fantasy setting like I'd initially planned. Instead, the story is set in the future, where humans (or whatever race I decide to be the player race) have taken control of a planet and are colonized there. Other races however, do not like this at all and want to do as much damage to the colony as possible, even destroy it! This is where the tower defense element comes in, you will take charge of the base/outpost commander, and create defense strategy across many different levels, increasing in difficulty.

In multiplayer, players do not have free reign of the map, and must work together. This is ensured by limiting a player's ability to place towers to certain portions of the map. This is completely dependant on the map, however it would generally be a 50/50 split in either direction.

Fast Rendering:
I briefly touched on writing a custom renderer before, however this may flesh it out a little. Initially, I had a tonne of DrawableGameComponents which rendered immediately using their own SpriteBatch, which, before you all go crazy on me, is a terrible idea and I soon realised the errors of my way.

Instead of doing the rendering themselves, they add to a backbuffer queue, which is then rendered in sequence once all of the other components have had the chance to update and draw. This allows all sprites to be drawn in 1 fell-swoop, keeping FPS at a constant 30 (this is hard limited so code is directly compatible with both Windows + Windows Phone environments) even with over 15,000 sprites being rendered. Memory usage is not really affected by my changes, but a definite improvement on both CPU usage and FPS is noted, especially when you consider that previously, drawing 50 sprites dropped the FPS to 20 and less ;-)

Cross-Platform Work:
As you probably (err, should!) know already, this game is going to be compatible with both Windows and Windows Phone, with network interoperability. Now then, things can be quite different between the platforms as I'm sure you're fully aware of, so I've had to do some work to alleviate the issues that I may run in to.

A good example is the way that settings (and related) are handled when it comes to writing files. Obviously on WP7 we have no direct access to the filesystem and have to use IsolatedStorage, however on Windows, we can write whatever we want, anywhere we want.

To accommodate for this fact, I have a cross platform IO class that provides a common interface for 2 APIs. It basically works using the defined constants for different platforms, and switches the main code based on this, whilst still providing a common API for reading/writing/creating files. It's certainly nothing special, but it's doing the job.

All in all, even though I haven't really made that progress with the game, I think that it's looking very good right now, and the story is fleshed out enough to actually start making the game properly.

Obviously there's still a gameplay test mode in here for now where you can spawn monsters (with a random path) at any time by right clicking, and place basic arrow towers by left clicking. This is working very well and will be available in the first playable test to show the capabilities of the engine (ie. test FPS with lots of sprites!).

I'm very happy with what's been done so far and can't wait to, after I release a playable test or two, get your guys' feedback! :)