Day 5: Python

January 6, 2010 by pekuja · Leave a Comment 

This update is hours late. That’s because I slept really late yesterday and didn’t have time to make an update. So, it’s the following morning, and I’ve just got my code to do pretty much the same thing it did yesterday, but with more bugs. In a possibly dumb move, I decided to switch my code over to Python.
The idea of this move was to improve my productivity over time, although obviously today’s progress is hindered by all the porting I had to do. I do now have the thing mostly ported, except for my config file loader, but that should be pretty quick to port. I also seem to have discovered a bug in SFML’s Python bindings, which is preventing me from turning image smoothing off when I have the view zoomed in, like I do to get that nice pixelated look. So basically now the game looks like an ugly mush. I’ll look into fixing the bindings soon.
Possibly the biggest part of the port was porting the map loader, because I couldn’t use much of the old code, as I wouldn’t be using the same XML library or the same base64 decoding and zlib decompression. Luckily, I was able to locate an existing Python implementation of a map loader for Tiled’s TMX map file format, written by DR0ID. Making it work with SFML made me bump into another bug in SFML or its Python bindings, when the map loader’s implementation was such that it would split a tilesheet into separate images for each tile, which seemed to fail in SFML. I decided to change the implementation so that I would just use subrects when rendering the tiles. I think that’s at least marginally faster anyhow.
I found myself also writing some particularly ugly code, when I decided to implement my player class and state machine states as Python modules with global (module wide) variables instead of encapsulating the code in a class. I suppose I just feel dirty for having “global variables” in my code. Also, I guess really the whole “singleton” approach is just harder to extend. It made the state machine states pretty simple though, as they don’t have any state information of their own. They’re just a bunch of functions.
I’ll try to make another progress post later tonight. Consider this yesterday’s post.