This post originated from an RSS feed registered with Python Buzz
by Rod Hyde.
Original Post: Corvids:
Feed Title: The landscape.
Feed URL: http://www.bloglines.com/blog/RodHyde/rss
Feed Description: The technical landscape through the eyes of an occasional indie games programmer who now uses Python as his language of choice.
Corvids is a simple 2d shooter game written in Python using a SWIG wrapper around the PTK library.
One thing that I have come to appreciate in Python is the ease at which I can implement callbacks and events. For example, I have implemented an event manager which enables functions to be called at some point in the future. The entire code for the event manager module is 35 lines, of which 14 are either comments or blank lines.
In the past (pre-Python) I have implemented event managers either using "Event" types or by using interfaces. The Python way of doing it is so much simpler.
It really is that simple. I can post any function I like without caring about what type it is or which class it belongs to. I think this is an example of Python's so-called "duck typing", ie, if it looks like a duck, walks like a duck and quacks like a duck then to all intents and purposes it is a duck.
What I particularly like about this, is that a function such as "make_zapper" can check if it is allowed to create a zapper, then, if it was unable to create one, post itself to the event manager to be called again after a random number of ticks. It makes it very, very easy to create and manage waves of aliens.