Mercurial > skaapsteker
annotate skaapsteker/cutscene.py @ 164:6233c0b8bbad
Remove unnecessary setting of _game_state in sub-class of Scene.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Wed, 06 Apr 2011 00:01:59 +0200 |
parents | 1e9599e48d7b |
children | 8d45715c587d |
rev | line source |
---|---|
134 | 1 # -*- coding: utf-8 -*- |
2 from __future__ import division | |
3 | |
4 import pygame | |
5 from pygame.locals import K_ESCAPE, K_q, KEYDOWN | |
6 | |
7 from . import data | |
8 from .engine import ChangeScene, Scene | |
9 from .widgets.text import Text, unindent_text | |
10 | |
11 class CutScene(Scene): | |
12 def __init__(self, game_state, text, background): | |
13 super(CutScene, self).__init__(game_state) | |
14 self.text = text | |
15 self.text_widget = Text(text, pygame.Rect(20, 20, 800-40, 600-40), | |
136
1e9599e48d7b
Simplistic text wrapping
Stefano Rivera <stefano@rivera.za.net>
parents:
134
diff
changeset
|
16 size=24, wrap=True) |
134 | 17 self.background = data.load_image('backgrounds/' + background) |
18 self.start_time = pygame.time.get_ticks() | |
19 self.run_time = 60000 # ms | |
20 | |
21 def draw(self, surface, engine): | |
22 viewport = surface.get_clip() | |
23 | |
24 # Scoll background back and forth: | |
25 max_pos = self.background.get_rect().width - viewport.width | |
26 bottom = self.background.get_rect().height - viewport.height | |
27 pos = ((pygame.time.get_ticks() - self.start_time) | |
28 % (self.run_time * 2)) * max_pos // (self.run_time) | |
29 if pos > max_pos: | |
30 pos = (2 * max_pos) - pos | |
31 surface.blit(self.background, viewport.topleft, | |
32 pygame.Rect((pos, bottom), viewport.size)) | |
33 | |
34 self.text_widget.draw(surface) | |
35 super(CutScene, self).draw(surface, engine) | |
36 | |
37 def dispatch(self, ev): | |
38 if ev.type is KEYDOWN: | |
39 if ev.key in(K_q, K_ESCAPE): | |
40 # Avoid circular import... | |
41 from .menuscene import MenuScene | |
42 ChangeScene.post(MenuScene(self._game_state)) | |
43 super(CutScene, self).dispatch(ev) | |
44 | |
45 | |
46 def opening_cutscene(game_state): | |
47 text = u""" | |
48 Many moons ago, an evil nine-tailed kitsune, a fearsome fox god, ruled the | |
49 land. | |
50 | |
51 It had many powers — the ability to shape shift, turn invisible, control | |
52 the elements. Its powers came from its majestic tails and the kitsune | |
53 guarded them ferociously. If any fox attained eight tails, it would battle | |
54 the kitsune for domination of the celestial world. To prevent this, the | |
55 kitsune stole the tails of all the foxes it encountered. | |
56 | |
57 The evil kitsune challenged every fox to a haiku contest. But the | |
58 competition was not fair, and the kitsune cheated every time. When it | |
59 defeated the poor fox, it stole its tail and threw it to the four winds. | |
60 | |
61 The kitsune stole your tail. Now it’s time to get it back. | |
62 """ | |
63 text = unindent_text(text) | |
64 return CutScene(game_state, text, 'background_01_back.png') |