diff skaapsteker/cutscene.py @ 243:4050e77dade6

Add support for background music tracks
author Neil Muller <drnlmuller@gmail.com>
date Thu, 07 Apr 2011 16:42:54 +0200
parents 691d2795ae3c
children 8c0c132b422f
line wrap: on
line diff
--- a/skaapsteker/cutscene.py	Thu Apr 07 15:01:23 2011 +0200
+++ b/skaapsteker/cutscene.py	Thu Apr 07 16:42:54 2011 +0200
@@ -9,7 +9,7 @@
 from .widgets.text import Text, unindent_text
 
 class CutScene(Scene):
-    def __init__(self, game_state, text, background):
+    def __init__(self, game_state, text, background, music=None):
         super(CutScene, self).__init__(game_state)
         self.text = text
         self.text_widget = Text(text, pygame.Rect(20, 20, 800-40, 600-40),
@@ -17,6 +17,9 @@
         self.background = data.load_image('backgrounds/' + background)
         self.start_time = pygame.time.get_ticks()
         self.run_time = 60000 # ms
+        self._background_music = None
+        if music and pygame.mixer.get_init():
+            self._background_music = data.filepath(music)
 
     def draw(self, surface, engine):
         viewport = surface.get_clip()
@@ -42,6 +45,15 @@
                 ChangeScene.post(MenuScene(self.game_state))
         super(CutScene, self).dispatch(ev)
 
+    def enter(self):
+        if self._background_music:
+            pygame.mixer.music.load(self._background_music)
+            pygame.mixer.music.play(-1)
+
+    def leave(self):
+        if self._background_music:
+            pygame.mixer.music.stop()
+
 
 def opening_cutscene(game_state):
     text = u"""