4
This is the full and final example from the Pygame Tutorial,
5
"How Do I Make It Move". It creates 10 objects and animates
8
Note it's a bit scant on error checking, but it's easy to read. :]
9
Fortunately, this is python, and we needn't wrestle with a pile of
16
from pygame.locals import *
18
#our game object class
20
def __init__(self, image, height, speed):
23
self.pos = image.get_rect().move(0, height)
25
self.pos = self.pos.move(self.speed, 0)
26
if self.pos.right > 600:
30
#quick function to load an image
32
path = os.path.join('data', name)
33
return pygame.image.load(path).convert()
39
screen = pygame.display.set_mode((640, 480))
41
player = load_image('player1.gif')
42
background = load_image('liquid.bmp')
43
screen.blit(background, (0, 0))
47
o = GameObject(player, x*40, x)
51
for event in pygame.event.get():
52
if event.type in (QUIT, KEYDOWN):
56
screen.blit(background, o.pos, o.pos)
59
screen.blit(o.image, o.pos)
61
pygame.display.update()
65
if __name__ == '__main__': main()