This happens often enough that I feel I should hang the words above my doorway: “When all else fails, use Python instead.” Optional addition: “Like you should have in the first place.”
After learning that educational lesson, shaking my fists impotently, and returning to my lair to nurse my wounds, I decided it was time to approach the problem again. I won’t deny I was somewhat inspired by the recently-released online textbook Making Games with Python & Pygame. I had been eyeing the pygame library for a while (Python being one my favorite scripting languages), and this new resource offered a great opportunity to dive right in. Obviously, the imminent arrival of this term’s final exams played no part in the timing of this project.
With that said, I’m not sure I would recommend the textbook as a great resource. It’s a handy thing for the novice game programmer, but it falls short as an instructional text. The book’s structure is partially to blame for this: each chapter lists the source code of a particular game, and then proceeds to give a line-by-line (or chunk-by-chunk) analysis of what the program does. This is fine at first; it lets you see the pygame functions & syntax in action. But at some point, you — the reader — are left to read between the lines: why is this function structured this way? Why does this need to be a global variable? Is this use of fonts really the best approach? At some point, a good teacher needs to step back from the gritty details to talk about big picture concepts; s/he needs to the address the “Why” in addition to the “How.” Unfortunately, that doesn’t happen here.
I could also gripe that the author has no voice, and that some of his coding habits/choices raise my eyebrows up to my hairline. But then I’d be nitpicking. Heaven knows I wouldn’t want to do that.
But anyway, after working through a couple chapters, I opened up IDLE (the development environment for Python) to cobble together a few pygame functions. After a couple days’ worth of lunchtimes, I had a fully-functional version of Conway’s Game of Life, with some rudimentary keyboard controls thrown in for good measure.
I’m not done with it: I’d like to change the keyboard controls into visual, clickable buttons (and add a few I missed). Also, letting the user modify the game clock is a mistake. I wanted to let you control the frequency at which each generation is run, but I shouldn’t have conflated that idea with modifying the frame rate (the number of frames displayed per second ). Because consequently, that determines how fast the game (and therefore, you) can perform some action. To draw it out, if you reduce the FPS to 1, not only do you see one generation per second, but there will be a significant lag between when you press a button and when the program reacts.
But these are good lessons. Frankly, that was the point of starting with Conway’s Game of Life: simple internal mechanics to allow me to focus on… well, everything else, really. Speaking of which, there’s also the question of distribution. I’d like to put this little program of mine online. Unfortunately, in order to run it, you would have to go through the same steps I did: install Python, install Pygame, and then use IDLE to run the source code. That seems a bit silly and excessive, so I’m going to explore to see if there are other options. Maybe it can be compiled into an app or an .exe, the kind of thing that will just run once on your computer. TBD.
In any case, I feel revitalized and rejuvenated. Solving this little problem has given me hope for all those other things I keep meaning to do. Deus Ex Python.