From d679de459e72fb86dfe71732f6512133782dbe9e Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sun, 18 May 2014 00:46:50 +0200 Subject: [PATCH] Autoscrolling credits --- naja/scenes/credits.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/naja/scenes/credits.py b/naja/scenes/credits.py index 9bb6d89..f967a72 100644 --- a/naja/scenes/credits.py +++ b/naja/scenes/credits.py @@ -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: -- 2.34.1