diff options
author | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-10-31 10:37:55 (GMT) |
---|---|---|
committer | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-10-31 10:37:55 (GMT) |
commit | 76278b70773a64b280fe0e83c4fdc31b5ca913fc (patch) | |
tree | 27a34cdd894dd9d9ee6a2f9a103a64f605167afa | |
parent | cb8392bc32bfd23bb4d99eb9871bb00ce1f5f449 (diff) |
Nice rotate
Signed-off-by: Agustin Zubiaga <aguz@sugarlabs.org>
-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: |