changeset 375:8631e38afc24

Usage cutscene (with minor CutScene refactoring)
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 09 Apr 2011 15:05:36 +0200
parents 9530b8dbda5f
children 4d6198b68cb9
files skaapsteker/cutscene.py skaapsteker/menuscene.py
diffstat 2 files changed, 43 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/skaapsteker/cutscene.py	Sat Apr 09 15:02:44 2011 +0200
+++ b/skaapsteker/cutscene.py	Sat Apr 09 15:05:36 2011 +0200
@@ -7,26 +7,27 @@
 from . import constants
 from . import data
 from .engine import ChangeScene, Scene
+from .levelscene import LevelScene
 from .widgets.text import Text, ButtonSet, TextButton, unindent_text
 
 class CutScene(Scene):
-    def __init__(self, game_state, soundsystem, text, background, music=None):
+    def __init__(self, game_state, soundsystem):
         super(CutScene, self).__init__(game_state, soundsystem)
-        self.background = data.load_image('backgrounds/' + background)
-        fill = pygame.Surface(self.background.get_size(), flags=SRCALPHA)
+        self._background_img = data.load_image('backgrounds/' + self.background)
+        fill = pygame.Surface(self._background_img.get_size(), flags=SRCALPHA)
         fill.fill((255, 255, 255, 128))
-        self.background.convert_alpha(fill)
-        self.background.blit(fill, (0, 0))
-        self.background.convert_alpha()
-        self.start_time = pygame.time.get_ticks()
-        self.run_time = 60000 # ms
+        self._background_img.convert_alpha(fill)
+        self._background_img.blit(fill, (0, 0))
+        self._background_img.convert_alpha()
+        self._start_time = pygame.time.get_ticks()
+        self._run_time = 60000 # ms
 
-        self._background_music = None
-        self._background_music = music
+        self._background_music = self.music
 
-        text_widget = Text(text, pygame.Rect(20, 20,
-                                             constants.SCREEN[0] - 40,
-                                             constants.SCREEN[1] - 40),
+        text_widget = Text(unindent_text(self.text),
+                           pygame.Rect(20, 20,
+                                       constants.SCREEN[0] - 40,
+                                       constants.SCREEN[1] - 40),
                            size=24, shadow='gray', wrap=True)
         self.widgets.append(text_widget)
 
@@ -46,13 +47,13 @@
         viewport = surface.get_clip()
 
         # Scoll background back and forth:
-        max_pos = self.background.get_rect().width - viewport.width
-        bottom = self.background.get_rect().height - viewport.height
-        pos = ((pygame.time.get_ticks() - self.start_time)
-               % (self.run_time * 2)) * max_pos // (self.run_time)
+        max_pos = self._background_img.get_rect().width - viewport.width
+        bottom = self._background_img.get_rect().height - viewport.height
+        pos = ((pygame.time.get_ticks() - self._start_time)
+               % (self._run_time * 2)) * max_pos // (self._run_time)
         if pos > max_pos:
             pos = (2 * max_pos) - pos
-        surface.blit(self.background, viewport.topleft,
+        surface.blit(self._background_img, viewport.topleft,
                      pygame.Rect((pos, bottom), viewport.size))
 
         super(CutScene, self).draw(surface, engine)
@@ -68,7 +69,7 @@
             self._soundsystem.play_background_music(self._background_music)
 
 
-def opening_cutscene(game_state, soundsystem):
+class OpeningCutScene(CutScene):
     text = u"""
     Many moons ago, an evil nine-tailed kitsune, a fearsome fox god, ruled the
     land.
@@ -85,5 +86,21 @@
 
     The kitsune stole your tail. Now it’s time to get it back.
     """
-    text = unindent_text(text)
-    return CutScene(game_state, soundsystem, text, 'background_01_back.png')
+    background = 'background_01_back.png'
+    music = None
+
+    def done(self, selected=None, data=None):
+        ChangeScene.post(LevelScene(self.game_state, self._soundsystem,
+                                    'temple.starting'))
+
+
+class UsageCutScene(CutScene):
+    text = u"""
+    Arrow keys control your movement.
+
+    Double-tap ← or β†’ to sprint,  ↑ to fly (when you can).
+
+    Z and X perform attacks.
+    """
+    background = 'background_01_back.png'
+    music = None
--- a/skaapsteker/menuscene.py	Sat Apr 09 15:02:44 2011 +0200
+++ b/skaapsteker/menuscene.py	Sat Apr 09 15:05:36 2011 +0200
@@ -1,7 +1,7 @@
 import pygame
 from pygame.locals import K_ESCAPE, K_q, KEYDOWN, QUIT
 
-from .cutscene import opening_cutscene
+from .cutscene import OpeningCutScene, UsageCutScene
 from .engine import ChangeScene, Scene
 from .levelscene import LevelScene
 from .widgets.text import Text, TextChoice
@@ -24,6 +24,7 @@
             ("Fishmonger's house", "fishmonger_house.starting"),
             ("Theatre", "theatre.starting"),
             ("Celestial plane", "celestial_plane.starting"),
+            ('Usage', 'usage'),
             ('Quit', 'quit'),
         ]
         if cur_game is not None:
@@ -37,7 +38,9 @@
         if data == 'resume':
             ChangeScene.post(self.cur_game)
         elif data == 'cutscene':
-            ChangeScene.post(opening_cutscene(self.game_state, self._soundsystem))
+            ChangeScene.post(OpeningCutScene(self.game_state, self._soundsystem))
+        elif data == 'usage':
+            ChangeScene.post(UsageCutScene(self.game_state, self._soundsystem))
         elif data == 'quit':
             pygame.event.post(pygame.event.Event(QUIT))
         else: