Mercurial > qq-pygrafix
changeset 1:5bbe81708710
init pygame before declaring classes, put copy-pasted code in control() into
a function
Pygame has to be initialized before the classes are declared, so that we
can load images as class variables.
| author | Radomir Dopieralski <moindev@sheep.art.pl> |
|---|---|
| date | Sat, 23 Aug 2008 00:24:27 +0200 |
| parents | 7b368da3f205 |
| children | a2d6566f8d2d |
| files | qq.py |
| diffstat | 1 files changed, 11 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/qq.py Sat Aug 23 00:06:18 2008 +0200 +++ b/qq.py Sat Aug 23 00:24:27 2008 +0200 @@ -4,6 +4,9 @@ import pygame from pygame.locals import * +pygame.init() +pygame.display.set_mode((360, 240)) + # Motion offsets for particular directions # N E S W DX = [0, 1, 0, -1] @@ -128,18 +131,17 @@ keys = pygame.key.get_pressed() def pressed(key): return self.pressed_key == key or keys[key] - if pressed(K_UP): - self.player.direction = 0 - self.player.animation = self.player.walk_animation() - elif pressed(K_DOWN): - self.player.direction = 2 + def walk(direction): + self.player.direction = direction self.player.animation = self.player.walk_animation() + if pressed(K_UP): + walk(0) + elif pressed(K_DOWN): + walk(2) elif pressed(K_LEFT): - self.player.direction = 3 - self.player.animation = self.player.walk_animation() + walk(3) elif pressed(K_RIGHT): - self.player.direction = 1 - self.player.animation = self.player.walk_animation() + walk(1) self.pressed_key = None def main(self): @@ -162,6 +164,4 @@ self.pressed_key = event.key if __name__ == "__main__": - pygame.init() - pygame.display.set_mode((360, 240)) Game().main()
