Mercurial > skaapsteker
comparison skaapsteker/cutscene.py @ 134:4713a2a3b0be
Initial cutscene screen
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Tue, 05 Apr 2011 00:06:07 +0200 |
parents | |
children | 1e9599e48d7b |
comparison
equal
deleted
inserted
replaced
133:aca8b7456c72 | 134:4713a2a3b0be |
---|---|
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._game_state = game_state | |
15 self.text = text | |
16 self.text_widget = Text(text, pygame.Rect(20, 20, 800-40, 600-40), | |
17 size=24) | |
18 self.background = data.load_image('backgrounds/' + background) | |
19 self.start_time = pygame.time.get_ticks() | |
20 self.run_time = 60000 # ms | |
21 | |
22 def draw(self, surface, engine): | |
23 viewport = surface.get_clip() | |
24 | |
25 # Scoll background back and forth: | |
26 max_pos = self.background.get_rect().width - viewport.width | |
27 bottom = self.background.get_rect().height - viewport.height | |
28 pos = ((pygame.time.get_ticks() - self.start_time) | |
29 % (self.run_time * 2)) * max_pos // (self.run_time) | |
30 if pos > max_pos: | |
31 pos = (2 * max_pos) - pos | |
32 surface.blit(self.background, viewport.topleft, | |
33 pygame.Rect((pos, bottom), viewport.size)) | |
34 | |
35 self.text_widget.draw(surface) | |
36 super(CutScene, self).draw(surface, engine) | |
37 | |
38 def dispatch(self, ev): | |
39 if ev.type is KEYDOWN: | |
40 if ev.key in(K_q, K_ESCAPE): | |
41 # Avoid circular import... | |
42 from .menuscene import MenuScene | |
43 ChangeScene.post(MenuScene(self._game_state)) | |
44 super(CutScene, self).dispatch(ev) | |
45 | |
46 | |
47 def opening_cutscene(game_state): | |
48 text = u""" | |
49 Many moons ago, an evil nine-tailed kitsune, a fearsome fox god, ruled the | |
50 land. | |
51 | |
52 It had many powers — the ability to shape shift, turn invisible, control | |
53 the elements. Its powers came from its majestic tails and the kitsune | |
54 guarded them ferociously. If any fox attained eight tails, it would battle | |
55 the kitsune for domination of the celestial world. To prevent this, the | |
56 kitsune stole the tails of all the foxes it encountered. | |
57 | |
58 The evil kitsune challenged every fox to a haiku contest. But the | |
59 competition was not fair, and the kitsune cheated every time. When it | |
60 defeated the poor fox, it stole its tail and threw it to the four winds. | |
61 | |
62 The kitsune stole your tail. Now it’s time to get it back. | |
63 """ | |
64 text = unindent_text(text) | |
65 return CutScene(game_state, text, 'background_01_back.png') |