diff options
author | Cristhofer Travieso <cristhofert97@gmail.com> | 2012-10-11 22:25:59 (GMT) |
---|---|---|
committer | Cristhofer Travieso <cristhofert97@gmail.com> | 2012-10-11 22:25:59 (GMT) |
commit | 9645a9fc56d9c6aac59b00fd88326cf6e7631f3d (patch) | |
tree | 7c2c99669aaa9eed17f37562c4e5696979ac5129 | |
parent | 909b03e7b06f4440e0c909dd7cdad8a449e11465 (diff) |
Add rotation
Signed-off-by: Cristhofer Travieso <cristhofert97@gmail.com>
-rwxr-xr-x | game.py | 38 |
1 files changed, 17 insertions, 21 deletions
@@ -9,31 +9,27 @@ class Game(glucosa.GameArea): def __init__(self): glucosa.GameArea.__init__(self) - self.events = glucosa.Events(self) - head = Head(self.events) + _events = glucosa.Events(self) + _head = Head(_events) - self.add_sprite(head) + self.add_sprite(_head) class Head(glucosa.Sprite): - def __init__(self, events): - image = glucosa.Image('images/head.png') - glucosa.Sprite.__init__(self, image, 0, 0) - events.connect('key-pressed', self.key_pressed) - - def key_pressed(self, event): - if event.is_pressed(event.K_UP): - self.rotation = 0 - self.y -= 10 - elif event.is_pressed(event.K_DOWN): - self.rotation = 180 - self.y += 10 - elif event.is_pressed(event.K_RIGHT): - self.rotation = 90 - self.x += 10 - elif event.is_pressed(event.K_LEFT): - self.rotation = 270 - self.x -= 10 + def __init__(self, _events): + _image = glucosa.Image('images/head.png') + glucosa.Sprite.__init__(self, _image, 100, 100) + _events.connect('key-pressed', self.key_pressed) + + def key_pressed(self, _event): + if _event.is_pressed(_event.K_UP): + self.set_rotation(0) + elif _event.is_pressed(_event.K_DOWN): + self.set_rotation(180) + elif _event.is_pressed(_event.K_RIGHT): + self.set_rotation(90) + elif _event.is_pressed(_event.K_LEFT): + self.set_rotation(270) if __name__ == '__main__': w = gtk.Window() |