Sunday, 31 August 2008

Now with text

Okay so I've not had a lot of time to make much progress this week but I did manage to spend a few minutes on my space invaders game. Looking back through previous issues of Linux Format - as suggested by someone on their forums - I came across a flash card tutorial which used PyGame as well. The bulk of the game was text based so there was a bit which explained about rendering and displaying text on the game window, porting this into my game was quite trivial and so now I have a life and score counter.

The thing to learn from this though is that it is always worth hanging onto those back issues, even though some of the stuff is now out of date there is still a wealth of knowledge buried in those pages.

Sunday, 24 August 2008

Game update

Been hacking around with the code from Linux Format and added in a few features. So we've now got a configurable alien setup where you can define the number of rows and the number of aliens in each row. I've set up a missile count so we start out at the number of rows plus 1, it also now removes a missile for each row you take out and checks to see if there are more missiles than aliens and removes them so there is always one less missile than there are aliens, until you get to one alien then obviously we keep that final missile in play.

The speeds and drops are now configurable and we've still got missile collision detection and a configurable number of lives. Still got a few more things I can do with it, and when I've done those I'll probably be able to think of a few more but this is a great project for cutting my teeth with Python.

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.

Wednesday, 13 August 2008

What's it all about

It's probably best to explain a little about myself before I try to explain what this blog is about.

I'm a developer living in Derbyshire, I've been using Linux for about 8 years now and I've been using it as my only OS at home for about 1 year. I spend 5 days a week churning out code at work using a Microsoft stack, so .Net and C# pre-dominantly, and I've been doing this along with using some other proprietary stuff for the last 9 years.

Now I'm one of these people who feels lucky doing the job I do because I love to code. I enjoy finding solutions to problems and writing the code to implement that solution, I also like helping other people out with their problems which is why I've done a few websites for people I know as well. I've been helping out in then free and open source community for a while now by helping out in forums and such but I've gotten to the point where I want to do more and this is where this blog comes in.

I have been on and off trying to pick up Python and migrate my existing skills over to Mono but I get distracted or start trying to do too much and end up never accomplishing anything so I'm setting myself a couple of goals:
  1. Teach myself Python
  2. Migrate my existing skill to Mono
  3. Do enough of goals 1 and 2 to start contributing towards an open-source project
The purpose of this blog is for me to post up my progress and how I manage or overcome various obstacles so that I can see how I'm doing. But more importantly it is to provide some kind of account so that anyone else who finds themselves in a similar situation to myself can learn from my experiences. This is not meant to be a tutorial blog of any kind although I may well post code snippets if I've done something which I think other people may benefit from (or I'm particularly happy with myself and want to share that).

To date I've managed to get to chapter 8 in the "Dive into Python" online book and I've written a Hello World app using Mono and MonoDevelop! So I've got some way to go, but then this is all about the journey.