Professional XNA Game Programming

I’ve been carrying around £40 worth of Waterstone’s vouchers for almost two years now and decided to stop wandering in there on the off-chance I would see something I really liked to use them up. Instead, I waited for something I really wanted and ordered it into the local branch.

I stumbled across the website of Benjamin Nitschke after reading an article about a Microsoft competition to write an XNA game in 4 days. I think you’ll agree that the results are staggering! So, it’s Ben’s book I decided to buy and here is a mini-review of it. The book is available now and I got it at Waterstone’s for £26.99.

Who is it for?

The book is aimed at newcomers to XNA but NOT newcomers to programming. In my opinion, this was a good move. There are a lot of C# books out there that cover the basics and I would have been disappointed had this book dedicated the initial chapters to re-iterating the basics and leaving less room for XNA goodness.

If you are a beginner, I would still recommend the book if you are interested in games programming as the initial chapters focus on simple games that could serve as an excellent way to brush up on your programming skills – much more fun than “Hello World!” It would be wise to have another text on pure C# programming though.

What it covers

Subjects covered (and this is an abbreviated list) are:

  • Setting up the development environment.
  • Using the Agile Method to develop games.
  • Simple 2D games such as Pong and Breakout.
  • Displaying a simple 3D model.
  • Using shaders, normal mapping and other techniques to produce professional visuals such as bloom, motion blur, glass effects etc.
  • Sound.
  • Landscape design and implementation.
  • Physics.

What’s refreshing is that by leaving out elementary basics, Benjamin is able to dedicate a large chunk of the book to advanced topics.

Each chapter tends to focus on a particular topic by showing how to implement it in a real game. There are a number of games created in the book ranging from the simple 2D games mentioned earlier, up to a fantastic 3D racing game in which you throw your car around a track that snakes in and out of a realistic rocky landscape.

Ben says early on how much he prefers XNA to DirectX programming and in fairness to him, he delivers the goods to back up his claims. The games he creates throughout the book certainly have that professional polish and don’t feel amateurish or compromised in any way.

How to use the book

The author does not list the code for each game in its entirety. Instead, he chooses to focus on the really important snippets of code that illustrate his point, leaving it up to the reader to download the source code from Wrox and read through to gain more insight. I think this is a good move on his part as I would have been just as disappointed with the book being ‘filled’ with code dumps, as I would if it dedicated chunks of pages to explaining how variables work.

When it comes to 3D, he focusses more on how to get XNA to do what you need it to do rather than explaining every single aspect of 3D, such as matrices. I’ve always found such texts on 3D very dry and at least with this method, you can actually get something done and become more comfortable with the concepts. It’s always less frustrating when you can actually experiment with real code to get instant feedback.

Agile

Benjamin is a big fan of the Agile Method and it really suits game development on XNA. I must admit I was initially shocked to see it promoted so much in the book but as I have progressed, the benefits have been realised. I won’t explain it in full but the process goes a bit like this:

  • Think about a part of the game you want to implement (eg drawing the paddle in breakout and moving it around).
  • Write a unit test which calls some (as yet uncoded) methods to accomplish this task.
  • Write the methods which actually do the work.
  • Run the unit test until you get the required result.

It’s a useful way of working as you focus on just one thing at a time and gradually tick off all the functionality your game requires. At the end you still have your unit tests so you can quickly identify any new bugs you have inadvertently created by just running each in isolation. I’ve always coded by dividing a problem into small chunks but this way formalises that a bit and really helps you focus on solving one problem at a time while doing it well.

Verdict

As you have hopefully gathered from this article, I like the book. It’s excellent value for money as it doesn’t re-iterate programming basics, doesn’t pad out the book with endless listings but does take you from being a beginner with XNA to being able to handle some very advanced topics. My gut instinct is once you have exhausted this book, you’ll be a pretty accomplished XNA games developer in your own right.