Monday 10 December 2007

The Beginner's Guide to Pygame, part one

It's been a week now since I first began learning PyGame, and in that time I've gone through several tutorials. Some have been great; others less so. As there are so many bobbing about on the interweb I thought I'd write a guide to which ones are best. Essentially a guide to beginning with PyGame really.
First off, the main source I've been using has been the PyGame documentation. This has links to several tutorials and is a great place to look if you're stuck. Next, you should check this tutorial for a good introduction that launches straight into a working example to get a feel for what writing PyGame programs is like.
At this point, you should get acquainted with the blit function. "How do I move an image?" provides an excellent introduction, starting by showing what the blit function does using basic Python and then moving on to show you how that's applied in PyGame. If this "blitting" is confusing you then that tutorial will almost definitely clear things up a bit.
Now that you have a decent understanding of how drawing things to the screen works, you should get more practice by using PyGame's built-in draw methods to make some funky line patterns, as taught by this tutorial. It also goes into colouring and animation as well, which could help later on.
Now, obviously a game's not a game if you can't control it in any way, so you have to have some way of getting events from the user. First, the mouse. This one also takes some of what you learned in the last tutorial by challenging you to make it draw a '+' on the screen where you click it. Then, once you've mastered that, this tutorial helps elaborate on what you've learned about events.
At the heart of every 2D game today is a system of sprites; that is, objects with images, properties and methods that you can use as characters, platforms, clouds or even blades of grass if you like. By following this article you too can learn to use them effectively in your games. And if you want to use collision detection as well, you'll want to look at this page.
Finally, you might be wondering how to bring all this knowledge together to make a full game. Well, this epic tutorial can help you there. It starts with a bit of revision of all the things you've learned about, then goes into taking you through the creation of a Pong remake. There's even a short maths lesson in there.
That's about as far as I've gotten so far; I will continue this guide later on. Either way, having done all the tutorials above you should have a basic knowledge and understanding of PyGame and should probably be able to start work on some simple games. I hope this article has been helpful in some way to those just starting with PyGame; good luck and happy coding.

1 comment:

  1. hi all,

    I am bit frustrated I use python 3.1.3 and pygame 1.9.1 and cannot find a simple basic tutorial on how to use this within my version of Python any help would be gratefully recieved.

    ReplyDelete