Autoscrolling credits
authorStefano Rivera <stefano@rivera.za.net>
Sat, 17 May 2014 22:46:50 +0000 (00:46 +0200)
committerStefano Rivera <stefano@rivera.za.net>
Sat, 17 May 2014 22:46:50 +0000 (00:46 +0200)
naja/scenes/credits.py

index 9bb6d89494fcb00e08018b6b3631c376a1f3eb24..f967a72f96cdda0d00be5f1b038a97223678a8a6 100644 (file)
@@ -3,6 +3,7 @@
 Credits scene.
 """
 
+import pygame
 import pygame.locals as pgl
 
 from naja.constants import KEYS
@@ -19,6 +20,7 @@ class CreditsScene(Scene):
 
     def __init__(self, state):
         super(CreditsScene, self).__init__(state)
+        self.autoscroll = 0
 
         background = ImageBox(
             (0, 0), "screens/splash.png")
@@ -26,7 +28,7 @@ class CreditsScene(Scene):
         self.add(TextWidget(
             (400, 300), 'CREDITS', colour='white', centre=True))
 
-        self.add(TextBoxWidget(
+        self.credits = TextBoxWidget(
             (400, 340), '\n'.join([
                 'A game about robots and bits and other things',
                 '',
@@ -52,7 +54,21 @@ class CreditsScene(Scene):
             ]),
             colour='white', padding=1,
             bg_colour=(0, 0, 0, 0), centre=True,
-            box_width=780, view_port=(780, 250)))
+            box_width=780, view_port=(780, 250))
+        self.add(self.credits)
+
+    def render_scene(self, surface):
+        if self.autoscroll is not None:
+            self.autoscroll += 1
+        if self.autoscroll >= 24:
+            fake_event = pygame.event.Event(pgl.KEYDOWN, key=pgl.K_DOWN)
+            self.credits.handle_event(fake_event)
+            self.autoscroll = 0
+
+    def handle_event(self, ev):
+        if ev.type == pgl.KEYDOWN:
+            self.autoscroll = None
+        return super(CreditsScene, self).handle_event(ev)
 
     def handle_scene_event(self, ev):
         if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT: