comparison skaapsteker/cutscene.py @ 492:b02d51e06c17

Add Victory CutScene (and refactor CutScenes)
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 09 Apr 2011 22:37:59 +0200
parents fb9258d66137
children 069fc6312ab8
comparison
equal deleted inserted replaced
491:6f110e347f30 492:b02d51e06c17
8 from . import data 8 from . import data
9 from .engine import ChangeScene, Scene 9 from .engine import ChangeScene, Scene
10 from .levelscene import LevelScene 10 from .levelscene import LevelScene
11 from .widgets.text import Text, ButtonSet, TextButton, unindent_text 11 from .widgets.text import Text, ButtonSet, TextButton, unindent_text
12 12
13
13 class CutScene(Scene): 14 class CutScene(Scene):
14 def __init__(self, game_state, soundsystem): 15 def __init__(self, game_state, soundsystem):
15 super(CutScene, self).__init__(game_state, soundsystem) 16 super(CutScene, self).__init__(game_state, soundsystem)
16 self._background_img = data.load_image('backgrounds/' + self.background)
17 fill = pygame.Surface(self._background_img.get_size(), flags=SRCALPHA)
18 fill.fill((255, 255, 255, 128))
19 self._background_img.convert_alpha(fill)
20 self._background_img.blit(fill, (0, 0))
21 self._background_img.convert_alpha()
22 self._start_time = pygame.time.get_ticks()
23 self._run_time = 60000 # ms
24
25 self._background_music = self.music 17 self._background_music = self.music
26
27 text_widget = Text(unindent_text(self.text),
28 pygame.Rect(20, 20,
29 constants.SCREEN[0] - 40,
30 constants.SCREEN[1] - 40),
31 size=24, shadow='gray', wrap=True)
32 self.widgets.append(text_widget)
33 18
34 button_set = ButtonSet() 19 button_set = ButtonSet()
35 # TODO: Dynamic position 20 # TODO: Dynamic position
36 button_set.append(TextButton("Continue", (20, constants.SCREEN[1] - 68), 21 button_set.append(TextButton("Continue", (20, constants.SCREEN[1] - 68),
37 size=24, color='red')) 22 size=24, color='red'))
40 25
41 def done(self, selected=None, data=None): 26 def done(self, selected=None, data=None):
42 # Avoid circular import... 27 # Avoid circular import...
43 from .menuscene import MenuScene 28 from .menuscene import MenuScene
44 ChangeScene.post((MenuScene,)) 29 ChangeScene.post((MenuScene,))
30
31 def dispatch(self, ev):
32 if ev.type is KEYDOWN:
33 if ev.key in(K_q, K_ESCAPE):
34 self.done()
35 super(CutScene, self).dispatch(ev)
36
37 def enter(self):
38 if self._background_music:
39 self._soundsystem.play_background_music(self._background_music)
40
41
42 class TextCutScene(CutScene):
43 def __init__(self, game_state, soundsystem):
44 super(TextCutScene, self).__init__(game_state, soundsystem)
45 self._background_img = data.load_image('backgrounds/' + self.background)
46 fill = pygame.Surface(self._background_img.get_size(), flags=SRCALPHA)
47 fill.fill((255, 255, 255, 128))
48 self._background_img.convert_alpha(fill)
49 self._background_img.blit(fill, (0, 0))
50 self._background_img.convert_alpha()
51 self._start_time = pygame.time.get_ticks()
52 self._run_time = 60000 # ms
53
54 text_widget = Text(unindent_text(self.text),
55 pygame.Rect(20, 20,
56 constants.SCREEN[0] - 40,
57 constants.SCREEN[1] - 40),
58 size=24, shadow='gray', wrap=True)
59 self.widgets.append(text_widget)
45 60
46 def draw(self, surface, engine): 61 def draw(self, surface, engine):
47 viewport = surface.get_clip() 62 viewport = surface.get_clip()
48 63
49 # Scoll background back and forth: 64 # Scoll background back and forth:
54 if pos > max_pos: 69 if pos > max_pos:
55 pos = (2 * max_pos) - pos 70 pos = (2 * max_pos) - pos
56 surface.blit(self._background_img, viewport.topleft, 71 surface.blit(self._background_img, viewport.topleft,
57 pygame.Rect((pos, bottom), viewport.size)) 72 pygame.Rect((pos, bottom), viewport.size))
58 73
59 super(CutScene, self).draw(surface, engine) 74 super(TextCutScene, self).draw(surface, engine)
60
61 def dispatch(self, ev):
62 if ev.type is KEYDOWN:
63 if ev.key in(K_q, K_ESCAPE):
64 self.done()
65 super(CutScene, self).dispatch(ev)
66
67 def enter(self):
68 if self._background_music:
69 self._soundsystem.play_background_music(self._background_music)
70 75
71 76
72 class OpeningCutScene(CutScene): 77 class OpeningCutScene(TextCutScene):
73 text = u""" 78 text = u"""
74 Many moons ago, an evil nine-tailed kitsune, a fearsome fox god, ruled the 79 Many moons ago, an evil nine-tailed kitsune, a fearsome fox god, ruled the
75 land. 80 land.
76 81
77 It had many powers — the ability to shape shift, turn invisible, control 82 It had many powers — the ability to shape shift, turn invisible, control
92 def done(self, selected=None, data=None): 97 def done(self, selected=None, data=None):
93 fox = self.game_state.world.fox 98 fox = self.game_state.world.fox
94 ChangeScene.post((LevelScene, '.'.join([fox.level, fox.doorway]))) 99 ChangeScene.post((LevelScene, '.'.join([fox.level, fox.doorway])))
95 100
96 101
97 class UsageCutScene(CutScene): 102 class UsageCutScene(TextCutScene):
98 text = u""" 103 text = u"""
99 Arrow keys control your movement. 104 Arrow keys control your movement.
100 105
101 Double-tap ← or → to sprint, ↑ to fly (when you can). 106 Double-tap ← or → to sprint, ↑ to fly (when you can).
102 107
104 """ 109 """
105 background = 'background_02_back.png' 110 background = 'background_02_back.png'
106 music = None 111 music = None
107 112
108 113
109 class CreditsCutScene(CutScene): 114 class CreditsCutScene(TextCutScene):
110 text = u""" 115 text = u"""
111 Credits: 116 Credits:
112 117
113 Programmers: Adrianna Pińska, Jeremy Thurgood, Neil Muller, Simon Cross, Stefano Rivera 118 Programmers: Adrianna Pińska, Jeremy Thurgood, Neil Muller, Simon Cross, Stefano Rivera
114 119
133 aesqe, 138 aesqe,
134 inferno 139 inferno
135 """ 140 """
136 background = 'background_03_back.png' 141 background = 'background_03_back.png'
137 music = None 142 music = None
143
144
145 class VictoryCutScene(CutScene):
146 music = None
147
148 def __init__(self, game_state, soundsystem):
149 super(VictoryCutScene, self).__init__(game_state, soundsystem)
150 self._background_img = data.load_image('backgrounds/victory-menu.png')
151
152 def draw(self, surface, engine):
153 surface.blit(self._background_img, (0, 0))
154 super(VictoryCutScene, self).draw(surface, engine)