Keeping score with PyGame

I’ve been playing with PyGame a little bit each night this week. Here’s tonight’s creation:

Dragon attack

This one allows the player to use the mouse to control a dragon (move and attack). If the dragon attacks the purple blob, the score increases. It uses rather sloppy rectangle based collision detection, but it works:

# Shrink rect and check for collision with target hitbox = self.rect.inflate(-5, -5) return hitbox.colliderect(target.rect)

And of course, it includes sound effects and background music. I’ve been using Audacity to convert mp3s to ogg for use with pygame.mixer.music:

# Load an play background music, continuous loop pygame.mixer.music.load('data/banco.ogg') pygame.mixer.music.play(-1, 0.0)

The Line By Line Chimp tutorial was extremely helpful in getting it all to work.

Leave a Reply