Saturday, 23 August 2008

Sods Law

As is normally the case, I finally settle down into doing something and I end up getting ill! Fortunately though I was starting to feel a bit better this morning and was inspired by the latest copy of Linux Format which turned up through my letterbox earlier this week.

One of the things I tend to do is flip straight to the back to see what kind of tutorials they're running and found to my delight one on Python game programming using PyGame, so I set about following the tutorial to see what I could do.

I could have easily skipped half the work at the first stage as LXF very kindly included the art-work from the tutorial on the cover disk but I figured I wanted to create my own, firstly so that the game felt more personal but also because the aliens look like a cross-dressing pac-man throwing kitchen funnels at the poor hero (if you're reading this Mike, it's this charm which makes them scary). I'm sure mine aren't that much better but like I said it makes the game feel more personal.

The code for the game is quite straight forward for a few reasons, firstly there is only one row of aliens, secondly the only collision detection is between the missiles and the hero/enemy and finally there is no on-screen text. So if you get hit it's game over and when you've killed them all it's game over. The only snag I hit was in setting the transparency for the graphics, the ones provided by LXF were probably already in the correct format whereas mine are not. Fortunately the PyGame surface class has a function called convert which sorts this out, so changing the line of code from:

self.bitmap = image.load(filename)
self.bitmap.set_colorkey((0, 0, 0))


self.bitmap = image.load(filename).convert()
self.bitmap.set_colorkey((0, 0, 0))

I suddenly ended up with transparent graphics.

Since then I've gone on and added in missile collision detection so I can blast their missiles out of the sky and I've added sprite collision detection, so if the aliens get to the bottom of the screen and they hit me it's game over. I also added lives into the game so I get three chances to lose now.

I'm possibly going to stick with this game for a few days now and add things like information to the display, more aliens and I might try and see if I can get it to become progressively more difficult. This is why I like game tutorials, they really get the imagination going.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.