Use Flashlight to drive the hack
authorStefano Rivera <stefano@rivera.za.net>
Sat, 17 May 2014 22:59:48 +0000 (00:59 +0200)
committerStefano Rivera <stefano@rivera.za.net>
Sat, 17 May 2014 22:59:58 +0000 (00:59 +0200)
naja/scenes/credits.py

index b3fd4bd0c1c752ee58e7d13d78a948c9e67b8eb3..8a6cfc238510eddf4cd8573e1697becc2be3ac44 100644 (file)
@@ -8,6 +8,7 @@ import pygame.locals as pgl
 
 from naja.constants import KEYS, FPS
 from naja.scenes.scene import Scene
+from naja.utils import Flashlight
 from naja.widgets.text import TextWidget, TextBoxWidget
 from naja.widgets.image_box import ImageBox
 from naja.events import SceneChangeEvent
@@ -20,7 +21,7 @@ class CreditsScene(Scene):
 
     def __init__(self, state):
         super(CreditsScene, self).__init__(state)
-        self.autoscroll = 0
+        self.flashlight = Flashlight(int(1.5 * FPS))
 
         background = ImageBox(
             (0, 0), "screens/splash.png")
@@ -58,16 +59,14 @@ class CreditsScene(Scene):
         self.add(self.credits)
 
     def render_scene(self, surface):
-        if self.autoscroll is not None:
-            self.autoscroll += 1
-        if self.autoscroll >= 1.5 * FPS:
-            fake_event = pygame.event.Event(pgl.KEYDOWN, key=pgl.K_DOWN)
-            self.credits.handle_event(fake_event)
-            self.autoscroll = 0
+        if self.flashlight is not None:
+            if self.flashlight.tick():
+                fake_event = pygame.event.Event(pgl.KEYDOWN, key=pgl.K_DOWN)
+                self.credits.handle_event(fake_event)
 
     def handle_event(self, ev):
         if ev.type == pgl.KEYDOWN:
-            self.autoscroll = None
+            self.flashlight = None
         return super(CreditsScene, self).handle_event(ev)
 
     def handle_scene_event(self, ev):