changeset 659:363b603794f5 pyntnclick

Re-add animations (and also fix some enter/leave event stuff)
author Neil Muller <neil@dip.sun.ac.za>
date Sun, 12 Feb 2012 14:45:06 +0200
parents 2703924c8c70
children dbec226debe3
files pyntnclick/engine.py pyntnclick/gamescreen.py
diffstat 2 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pyntnclick/engine.py	Sun Feb 12 14:25:27 2012 +0200
+++ b/pyntnclick/engine.py	Sun Feb 12 14:45:06 2012 +0200
@@ -48,6 +48,8 @@
                                                                ev.data)
                 else:
                     self._screen.dispatch(ev)
+            # Ping the screen / scene
+            self._screen.animate()
             surface = pygame.display.get_surface()
             self._screen.draw(surface)
             flip()
@@ -88,6 +90,12 @@
     def dispatch(self, ev):
         self.container.event(ev)
 
+    def animate(self):
+        """Called every tick - used for peroidic events, etc.
+
+           Interested classes are expected to override this"""
+        pass
+
     def draw_background(self):
         self.surface.fill(pygame.Color('gray'))
 
--- a/pyntnclick/gamescreen.py	Sun Feb 12 14:25:27 2012 +0200
+++ b/pyntnclick/gamescreen.py	Sun Feb 12 14:45:06 2012 +0200
@@ -127,6 +127,10 @@
         # of what happens
         result = self.game.check_enter_leave(self.screen)
         handle_result(result, self)
+        if self.game.current_detail:
+            self.game.current_detail.animate()
+        else:
+            self.game.current_scene.animate()
 
     def mouse_move(self, event, widget):
         if self.game.current_detail:
@@ -275,6 +279,7 @@
         self.running = False
         self.create_initial_state = self.gd.initial_state
         self.container.add_callback(KEYDOWN, self.key_pressed)
+        self.state_widget = None
 
     def _clear_all(self):
         for widget in self.container.children[:]:
@@ -299,6 +304,11 @@
 
         self.running = True
 
+    def animate(self):
+        """Animate the state widget"""
+        if self.state_widget:
+            self.state_widget.animate()
+
     def key_pressed(self, event, widget):
         if event.key == K_ESCAPE:
             self.change_screen('menu')