diff options
-rwxr-xr-x | game.py | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -2,6 +2,7 @@ import glucosa import gtk +import gobject class Game(glucosa.GameArea): @@ -22,15 +23,34 @@ class Head(glucosa.Sprite): glucosa.Sprite.__init__(self, _image, 600, 400) _events.connect('key-pressed', self._key_pressed) + self._to_rotate = 0 + def _key_pressed(self, _event): if _event.is_pressed(_event.K_UP): - self.set_rotation(0) + self._to_rotate = 0 elif _event.is_pressed(_event.K_DOWN): - self.set_rotation(180) + self._to_rotate = 180 elif _event.is_pressed(_event.K_RIGHT): - self.set_rotation(90) + self._to_rotate = 90 elif _event.is_pressed(_event.K_LEFT): - self.set_rotation(270) + self._to_rotate = 270 + + gobject.timeout_add(45, self.rotate) + + def rotate(self): + _continue = True + if self.rotation > self._to_rotate: + self.rotation -= 1 + + elif self.rotation < self._to_rotate: + self.rotation += 1 + + elif self.rotation == self._to_rotate: + _continue = False + + self.emit('update') + + return _continue def _update(self, widget, event): if self.rotation == 0: |