Developing Games with Python10/04/2001
When the going gets tough, the tough go gaming. Or, at least, they aren't giving up their games. The tech industry is in a slump, but the computer gaming industry is hanging in there. I am beginning to envy my neighbor, Jared, an artist for a Seattle-based gaming company. Maybe it's time to learn a bit more about computer games. As a Python programmer, perhaps the best place to start is with PyGame, Python's Simple DirectMedia Layer (SDL) binding.
SDL is the tool used by Loki Software to port Civilization: Call to Power and other games to Linux. SDL, however, is a cross platform tool. Is is available for both Windows and Linux. Unfortunately, SDL may never go where the money is, namely, developing directly for game boxes. SDL's open source license, a benefit to you as a developer, doesn't mix well with the proprietary licenses of Sega and Sony software development kits. SDL has, however, been ported to Linux running on Sony Playstation2 and Sega Dreamcast. (Jared was interested to find out I use Linux. He says it is the operating system of choice among developers at his company.) Aside from games, SDL has been used to write mpeg players, a midi editor, and a paint program. One of my favorite SDL applications is a musical lava lamp Synaesthesia, which represents music graphically as you play it. In gaming and beyond, SDL's future seems bright. Add Python and you have an excellent tool for quickly learning to program games.
Because most PyGame projects are small in size, simple 2D shooters and strategy games, they are easy to study and experiment with. Like SDL, PyGame is being used for more than just games. If you want to work your way into game programming from something that seems more familiar, you could take a look at Frank Raiser's PyFile, a multimedia file browser, or Ryan Kulla's image viewer, IMGV. Pete Shinners, PyGame's maintainer, also hosts a code repository, with algorithms and effects for you to use in your own projects.
Another PyGame project to look at, for both game development as well as other application development, is PyUI. Sean Riley announced PyUI, a user interface library, in May. It is written in pure Python and uses PyGame as its 2D renderer. PyOpenGL provides some 3D support, and the Python Image Library is used to generate some images. Currently at release 0.7, it's still rough and has little documentation. It does contain several examples, though. They provide a launching point for further exploration.
PyUI provides a front end for multiple renderers, not just PyGame. Version 0.7 includes support for Tk and some support for a Win32 GDI renderer as well, but its primary use is for creating portable user interfaces in PyGame. Rendered by PyGame, PyUI doesn't look much like other user interfaces. Your artistic expression can run wild with PyGame, maybe a little too wild. For most applications you want to design something your users will recognize, but PyUI can be fun to explore.
Finally, there are a few PyGame based game engines you can use when you are ready to plunge into game programming: Pyzzle, for Myst-like games, PyPlace for isometric games like Civilization. These are both listed on the PyGame Projects page. Another engine in the works is AutoManga, a cel-based animation engine. Beyond Python, there are many more tools for SDL game development to launch you on your gaming career.
Stephen Figgins administrates Linux servers for Sunflower Broadband, a cable company.
Read more Python News columns.
Return to the Python DevCenter.