Index of /python/lectures/pygame

[ICO]NameLast modifiedSizeDescription

[PARENTDIR]Parent Directory   -  
[TXT]trail.py 2009-06-30 02:03 2.4K 
[   ]particles.py 2009-06-30 02:03 841  
[   ]draw.py 2009-06-30 02:03 614  
[   ]munch.py 2009-06-30 02:03 594  

Pygame/surfarray lecture

Pygame/surfarray lecture

On http://wiki.python.org.il/Meeting_30_January_2007, I gave a lecture about Pygame (an SDL wrapper) and Numeric, bridged by the pygame.surfarray module.

There were no slides but these code examples were presented, together with interactive usage. The libraries have extensive documentation and nice tutorials. For the particular topic of combining Pygame with Numeric, see see the surfarray introduction tutorial.

Examples

I wanted to implement a game where by waving around your "magic wand" (== mouse) you can create clouds of "raw magic" that move around and interact between them. A goal can be defined then, e.g. hit the opponent's (assuming networking or AI) side of the screen with as much of your magic as possible, while defending your side from his magic. This led me to entitle the lecture "Pygame, Numeric and magic fields", which created confusion (people probably assumed that I meant "fields" in the OO sense, i.e. things like __getattr__, while I meant them in the phisical sense :-).

Naturally, I didn't come close to that in the one day I took to prepare, but I did write some simple yet somewhat fun examples that were enough for the purposes of the lecture:

draw.py
A minimal example of a Pygame main loop: draw by pressing mouse buttons and moving the mouse.
munch.py
First example of Pygame displaying Numeric arrays: the classic "munching squares" pattern.
particles.py
A trivial particle engine in pure Pygame: particles move and slow down, until they stop or leave the screen.
trail.py
The final Pygame + Numeric example: particle leave a trail on a Numeric array, which undergoes blurring and also accelerates the particles.

Games

The sites of Pygame and SDL include many games, some of them mature and very enjoyable. Notably, see SolarWolf (written by Pygame's author Pete Shinners).

There are two relevant game competitions: The Ludum Dare 48-hours competition (solo, any language) and the Pyweek challenge (solo/groups, one week, Python). They have similar rules: you can use existing libraries like Pygame but must write all game logic from scratch during the competition time frame. Sounds like lots of fun. The next Pyweek will start on 2007-04-01, and I hope to organize an Israeli team! We'll discuss the details on the Python-IL mailing list...