source: skaapsteker/cutscene.py

Last change on this file was 576:0dfb62814de6, checked in by Stefano Rivera <stefano@…>, 12 years ago

Further usage improvements

File size: 5.4 KB
Line 
1# -*- coding: utf-8 -*-
2from __future__ import division
3
4import pygame
5from pygame.locals import K_ESCAPE, K_q, KEYDOWN, SRCALPHA
6
7from . import constants
8from . import data
9from .engine import ChangeScene, Scene
10from .levelscene import LevelScene
11from .widgets.text import Text, ButtonSet, TextButton, unindent_text
12
13
14class CutScene(Scene):
15 def __init__(self, game_state, soundsystem):
16 super(CutScene, self).__init__(game_state, soundsystem)
17 self._background_music = self.music
18
19 button_set = ButtonSet()
20 # TODO: Dynamic position
21 button_set.append(TextButton("Continue", (20, constants.SCREEN[1] - 68),
22 size=24, color='red'))
23 button_set.callbacks.append(self.done)
24 self.widgets.append(button_set)
25
26 def done(self, selected=None, data=None):
27 # Avoid circular import...
28 from .menuscene import 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 and self._soundsystem:
39 self._soundsystem.play_background_music(self._background_music)
40
41
42class TextCutScene(CutScene):
43 wrap = True
44
45 def __init__(self, game_state, soundsystem):
46 super(TextCutScene, self).__init__(game_state, soundsystem)
47 self._background_img = data.load_image('backgrounds/' + self.background)
48 fill = pygame.Surface(self._background_img.get_size(), flags=SRCALPHA)
49 fill.fill((255, 255, 255, 128))
50 self._background_img.convert_alpha(fill)
51 self._background_img.blit(fill, (0, 0))
52 self._background_img.convert_alpha()
53 self._start_time = pygame.time.get_ticks()
54 self._run_time = 60000 # ms
55
56 text_widget = Text(unindent_text(self.text),
57 pygame.Rect(20, 20,
58 constants.SCREEN[0] - 40,
59 constants.SCREEN[1] - 40),
60 size=24, shadow='gray', wrap=self.wrap)
61 self.widgets.append(text_widget)
62
63 def draw(self, surface, engine):
64 viewport = surface.get_clip()
65
66 # Scoll background back and forth:
67 max_pos = self._background_img.get_rect().width - viewport.width
68 bottom = self._background_img.get_rect().height - viewport.height
69 pos = ((pygame.time.get_ticks() - self._start_time)
70 % (self._run_time * 2)) * max_pos // (self._run_time)
71 if pos > max_pos:
72 pos = (2 * max_pos) - pos
73 surface.blit(self._background_img, viewport.topleft,
74 pygame.Rect((pos, bottom), viewport.size))
75
76 super(TextCutScene, self).draw(surface, engine)
77
78
79class OpeningCutScene(TextCutScene):
80 text = u"""
81 Many moons ago, an evil nine-tailed kitsune, a fearsome fox god, ruled the
82 land.
83
84 It had many powers — the ability to shape shift, turn invisible, control
85 the elements. Its powers came from its majestic tails and the kitsune
86 guarded them ferociously. If any fox attained eight tails, it would battle
87 the kitsune for domination of the celestial world. To prevent this, the
88 kitsune stole the tails of all the foxes it encountered.
89
90 The evil kitsune challenged every fox to a haiku contest. But the
91 competition was not fair, and the kitsune cheated every time. When it
92 defeated the poor fox, it stole its tail and threw it to the four winds.
93
94 The kitsune stole your tail. Now it’s time to get it back.
95 """
96 background = 'background_01_back.png'
97 music = 'music/ambient japanese music 2.ogg'
98
99 def done(self, selected=None, data=None):
100 fox = self.game_state.world.fox
101 ChangeScene.post((LevelScene, '.'.join([fox.level, fox.doorway])))
102
103
104class UsageCutScene(TextCutScene):
105 wrap = False
106 text = u"""
107 Arrow keys control your movement.
108 Z and X to perform attacks.
109 ↓ to pick up / drops items or perform actions.
110
111
112 With the right tails, you can do the following:
113 C to shift shape.
114 V to make you invisible.
115 Double-tap ← or → to sprint.
116 Double-tap ↑ to fly.
117
118
119 In conversation use ↑ and ↓ to select a response
120 and ↲ to speak.
121
122
123 Dvorak users: Pass the --dvorak command-line argument
124 """
125 background = 'background_02_back.png'
126 music = None
127
128
129class CreditsCutScene(TextCutScene):
130 text = u"""
131 Credits:
132
133 Programmers: Adrianna Pińska, Jeremy Thurgood, Neil Muller, Simon Cross, Stefano Rivera
134
135 Art: Oliver Hambsch
136
137 Story: Anna Malczyk
138
139 Music & Sound Effects:
140 OLPC Sound Library: Richard Boulanger;
141 The Free Sound Project:
142 Connor Purcell,
143 Nathan Hill,
144 Donnie Thompson,
145 Muki,
146 Tom Potter,
147 Kayden Riggs,
148 ITE,
149 GRSites.com,
150 dobroide,
151 pauliep83,
152 nextmaking,
153 aesqe,
154 inferno
155 """
156 background = 'background_03_back.png'
157 music = 'music/ambient japanese music 3.ogg'
158
159
160class VictoryCutScene(CutScene):
161 music = 'music/ambient japanese music 1.ogg'
162
163 def __init__(self, game_state, soundsystem):
164 super(VictoryCutScene, self).__init__(game_state, soundsystem)
165 self._background_img = data.load_image('backgrounds/victory-menu.png')
166
167 def draw(self, surface, engine):
168 surface.blit(self._background_img, (0, 0))
169 super(VictoryCutScene, self).draw(surface, engine)
Note: See TracBrowser for help on using the repository browser.