Use Flashlight to drive the hack
[naja.git] / naja / scenes / credits.py
1 # coding: UTF-8
2 """
3 Credits scene.
4 """
5
6 import pygame
7 import pygame.locals as pgl
8
9 from naja.constants import KEYS, FPS
10 from naja.scenes.scene import Scene
11 from naja.utils import Flashlight
12 from naja.widgets.text import TextWidget, TextBoxWidget
13 from naja.widgets.image_box import ImageBox
14 from naja.events import SceneChangeEvent
15
16
17 class CreditsScene(Scene):
18     """
19     List those responsible.
20     """
21
22     def __init__(self, state):
23         super(CreditsScene, self).__init__(state)
24         self.flashlight = Flashlight(int(1.5 * FPS))
25
26         background = ImageBox(
27             (0, 0), "screens/splash.png")
28         self.add(background)
29         self.add(TextWidget(
30             (400, 300), 'CREDITS', colour='white', centre=True))
31
32         self.credits = TextBoxWidget(
33             (400, 340), '\n'.join([
34                 'A game about robots and bits and other things',
35                 '',
36                 'by',
37                 '',
38                 u'Adrianna PiƄska, David Sharpe, Jeremy Thurgood, '
39                 u'Neil Muller, Simon Cross & Stefano Rivera',
40                 '',
41                 'Special thanks to:',
42                 '',
43                 'Desilu Crossman',
44                 'for snacks and tutorial inspiration',
45                 '',
46                 'Bearnard Hibbins, Graham Inggs,',
47                 'and William Stewart',
48                 'for playtesting and finding bugs',
49                 '',
50                 'Music by Rolemusic:',
51                 'http://rolemusic.sawsquarenoise.com/',
52                 '',
53                 'Out of credits. Insert coin.',
54                 '(Press ESC to return to the menu.)',
55             ]),
56             colour='white', padding=1,
57             bg_colour=(0, 0, 0, 0), centre=True,
58             box_width=780, view_port=(780, 250))
59         self.add(self.credits)
60
61     def render_scene(self, surface):
62         if self.flashlight is not None:
63             if self.flashlight.tick():
64                 fake_event = pygame.event.Event(pgl.KEYDOWN, key=pgl.K_DOWN)
65                 self.credits.handle_event(fake_event)
66
67     def handle_event(self, ev):
68         if ev.type == pgl.KEYDOWN:
69             self.flashlight = None
70         return super(CreditsScene, self).handle_event(ev)
71
72     def handle_scene_event(self, ev):
73         if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
74             from naja.scenes.menu import MenuScene
75             SceneChangeEvent.post(MenuScene)
76             return