Thursday, August 20, 2009

Pygame2 example game finished

Early this summer, when my Google Summer of Code proposal to the Pygame project was rejected, I told the coordinator that I would nonetheless contribute to the project over the summer. I planned on writing examples and tutorials for the Pygame2 multimedia library. Unfortunately, events conspired to prevent me from writing the examples. I had tremendous difficulty installing Pygame2 properly and no time to find the problems: I finally overcame my installation problems only two weeks ago.

Composite screenshot of all four skins Four graphical skins for your gaming pleasure!

However, I spent a great deal of time over the last week writing my first example for Pygame2. It's based on the oldalien.py demo distributed with the original Pygame, but I greatly expanded its scope. I tried to demonstrate as much of the library as I could, but I ended up using only a sliver of the library's functionality. The finished example demonstrates Surface handling, vector drawing with pygame2.sdlext.draw, text rendering with pygame2.sdlttf, image loading with pygame2.sdlimage, and sound effects with pygame2.sdlmixer. It's not an exhaustive demonstration of those concepts, but I think it's a good starting point for exploration of the library.

In addition to showing off the Pygame2 library, I tried to demonstrate best practices. I encapsulated the object instantiation and sprite drawing in external factories, allowing users with incomplete installations of Pygame2 to still see parts of the example. I only have to switch factories to drastically change the look of the game. Most importantly, I expunged the global variables from all the classes. The game still uses a couple long-life variables, but I eliminated the unnecessary ones.

If you'd like to see my uber-example in action, you can get it from its SVN repository or download it as a .tar.gz archive. If you have any trouble with the game, let me know.