While playing through Pokémon Emerald, I started thinking about the actual logic behind the movement of the character and its interaction with the game world. A bare-bones movement routine seemed simple enough to implement, and I was challenged by reading that Satoshi Tajiri originally wrote his demo of a top-down sidescroller for Pocket Monsters in just a few days— in Z80 assembly!
For this project I ended up using Python (my second Python program after the Monopoly script) with the PyGame library. PyGame is a simple SDL wrapper with Python bindings for useful data structures and operations like timing and blitting.
I improved over even Emerald with fine-grained layer behavior (allowing complex tile layering tricks like in Run 5) and a sticky viewport that stays within the world boundaries. Click the links above and below to see the demo in action.
The rightmost screenshot at the top of the page shows Tiled editing one map file included with my demo. With Tiled I can import a tileset sheet and paint tiles in layers to create areas without needing to do custom graphics work. My code supports blocking volumes for distinguishing walkable tiles (such as grass) from object tiles (such as houses), and Tiled has built-in functionality for demarcating such areas.
All of the map data is exported in XML format (sample), which my demo can parse using SAX.
The individual source links for browsing are above. The easiest way to play the demo yourself on Windows is to make sure you have installed Python 2.6 and the corresponding pygame release. Then download and extract the source archive and double-click main.py.
The arrow keys move your character. Holding
space will disable the frame limiter, allowing you to walk quickly if you have a good processor. Holding
r will record the window's output to the
The demo now by default uses a new map different from the test map shown above. This new map shows multiple tileset support, using graphics from both tilesets included in the zip download.