Mercurial > skaapsteker
comparison skaapsteker/cutscene.py @ 262:de60329cfc9f
Factor out sound stuff
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Fri, 08 Apr 2011 11:29:37 +0200 |
parents | 8c0c132b422f |
children | 62b98bea56bf |
comparison
equal
deleted
inserted
replaced
261:7668243695f4 | 262:de60329cfc9f |
---|---|
7 from . import data | 7 from . import data |
8 from .engine import ChangeScene, Scene | 8 from .engine import ChangeScene, Scene |
9 from .widgets.text import Text, ButtonSet, TextButton, unindent_text | 9 from .widgets.text import Text, ButtonSet, TextButton, unindent_text |
10 | 10 |
11 class CutScene(Scene): | 11 class CutScene(Scene): |
12 def __init__(self, game_state, text, background, music=None): | 12 def __init__(self, game_state, soundsystem, text, background, music=None): |
13 super(CutScene, self).__init__(game_state) | 13 super(CutScene, self).__init__(game_state, soundsystem) |
14 self.background = data.load_image('backgrounds/' + background) | 14 self.background = data.load_image('backgrounds/' + background) |
15 self.start_time = pygame.time.get_ticks() | 15 self.start_time = pygame.time.get_ticks() |
16 self.run_time = 60000 # ms | 16 self.run_time = 60000 # ms |
17 | 17 |
18 self._background_music = None | 18 self._background_music = None |
19 if music and pygame.mixer.get_init(): | 19 self._background_music = music |
20 self._background_music = data.filepath(music) | |
21 | 20 |
22 text_widget = Text(text, pygame.Rect(20, 20, 800-40, 600-40), | 21 text_widget = Text(text, pygame.Rect(20, 20, 800-40, 600-40), |
23 size=24, shadow='gray', wrap=True) | 22 size=24, shadow='gray', wrap=True) |
24 self.widgets.append(text_widget) | 23 self.widgets.append(text_widget) |
25 | 24 |
54 self.done() | 53 self.done() |
55 super(CutScene, self).dispatch(ev) | 54 super(CutScene, self).dispatch(ev) |
56 | 55 |
57 def enter(self): | 56 def enter(self): |
58 if self._background_music: | 57 if self._background_music: |
59 pygame.mixer.music.load(self._background_music) | 58 self._soundsystem.play_background_music(self._background_music) |
60 pygame.mixer.music.play(-1) | |
61 | |
62 def leave(self): | |
63 if self._background_music: | |
64 pygame.mixer.music.stop() | |
65 | 59 |
66 | 60 |
67 def opening_cutscene(game_state): | 61 def opening_cutscene(game_state, soundsystem): |
68 text = u""" | 62 text = u""" |
69 Many moons ago, an evil nine-tailed kitsune, a fearsome fox god, ruled the | 63 Many moons ago, an evil nine-tailed kitsune, a fearsome fox god, ruled the |
70 land. | 64 land. |
71 | 65 |
72 It had many powers — the ability to shape shift, turn invisible, control | 66 It had many powers — the ability to shape shift, turn invisible, control |
80 defeated the poor fox, it stole its tail and threw it to the four winds. | 74 defeated the poor fox, it stole its tail and threw it to the four winds. |
81 | 75 |
82 The kitsune stole your tail. Now it’s time to get it back. | 76 The kitsune stole your tail. Now it’s time to get it back. |
83 """ | 77 """ |
84 text = unindent_text(text) | 78 text = unindent_text(text) |
85 return CutScene(game_state, text, 'background_01_back.png') | 79 return CutScene(game_state, soundsystem, text, 'background_01_back.png') |