Saturday, December 03, 2005

Game Boy Adventures

I'm in the middle of what is turning into a fairly long vacation, during which I've been doing as much research and development for my video game as I can. This project has been in development off and on for over five years. First it was called zhack, then Seelie. Now I'm calling it Faeries Underground. I've started probably seven or eight implementations in numerous different languages and environments. I've gotten the software playable exactly once, when I devoted myself to that seven-day roguelike effort. During this time the design of the game itself has been greatly refined without its nature changing very much: It's a roguelike game based primarily on Scottish, English and Welsh faerie lore. However there was one thread that all of my implementations have had in common: They were all designed to be played on a PC.

This has changed with my most recent implementation of the game. After I lost my Game Boy Advance I was delighted to learn about the release of the Game Boy Micro. The Micro is tiny Game Boy Advance system with a rechargable battery and a superb backlit screen, and I bought one as soon as I could. This is the ideal portable game platform for my needs, and it happens to be a good platform for development as well.

There are many reasons why a homebrew developer would want to develop games for the Game Boy, especially in comparison to other modern platforms. The most important reason for me is that the barrier to entry is lower, especially in terms of creative resources. Modern 3D games require an enourmous amount of work (and fancy software operated by skilled artists) in order to create the textures and models that make up the game environment. Creating tiny 2-D sprites is within even my ability, and there are public domain tilesets available as well. In addition to this, all of the software tools needed to create games for the Game Boy Advance are available for free. This may seem like a big deal, and I suppose it is, but my computers have been running on Free Software for years so I'm rather spoiled in that regard.

From a technical perspective, this project has been extremely educational. As is often the case when I embark on a new development effort, there are many new things I need to learn in order to get the job done. The development of past incarnations of this game has prompted me to learn C, Objective-C and Python as well as countless associated APIs and techniques. Although C (supplemented with very low-level assembly code) is the language used for creating most Game Boy games, I am too accustomed to object-oriented software design and resent having to shoehorn C into that role every time I use it for something non-trivial. Therefore I am doing something I never thought I would do: I'm learning the C++ programming language.

I have rejected C++ countless times for other projects, for a number of reasons. For starters, I think Objective-C is a much more sane approach to object-oriented programming in C. Also there are many features of the C++ language that are of marginal usefulness and have little or nothing to do with OO programming. In this case, there is no easy path to Objective-C programming on the Game Boy and the associated API and environment is too heavy for such a small platform anyway. As for the C++ language misfeatures, I am avoiding that minefield by using a small subset of the C++ language, basically just enough to allow for object-oriented programming. Specifically I am avoiding use of the entire C++ standard library as well as features such as templates, exceptions, streams, etc. The fanciest facility I've used so far is virtual classes. I think the core C++ language provides a reasonable set of trade-offs on a small system like the Game Boy.

In addition to learning C++, I decided to use test-driven development (TDD) for this project. I have researched TDD before on a limited basis but this is my first non-trivial TDD project, and certainly my first using C++. After a short search I found a great C++ testing package called CxxTest. Using tests to develop my game has had a surprising impact. Constantly having to write tests for my code has prevented me from going down the wrong path countless times and the influence on my design has been very positive. In fact, it was the requirement that my code be testable that caused me to invent a way to make my game portable across systems that are not the Game Boy!

This idea is based on a simple principle that was not immediately obvious to me: Properly designed software targeting an embedded platform (like the Game Boy) should be easily portable to a more powerful machine, since the functionality required by the original software is a subset of what a full-featured computer would provide. This realization came when I was looking for a way to test my Game-Boy dependent code. I noticed that that functionality I would need to abstract the platform-dependent stuff for testing would also allow me to provide platform-specific implementations for systems other than the Game Boy.

I also discovered that mine is not the first attempt to create a roguelike game for the Game Boy. The game POWDER is available for the Game Boy, and there is are even ports of the original rogue and hack as well.