Mercurial > skaapsteker
comparison skaapsteker/cutscene.py @ 247:8c0c132b422f
Button widget for cutscene
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Thu, 07 Apr 2011 19:25:48 +0200 |
parents | 4050e77dade6 |
children | de60329cfc9f |
comparison
equal
deleted
inserted
replaced
246:8dee25fd070d | 247:8c0c132b422f |
---|---|
4 import pygame | 4 import pygame |
5 from pygame.locals import K_ESCAPE, K_q, KEYDOWN | 5 from pygame.locals import K_ESCAPE, K_q, KEYDOWN |
6 | 6 |
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, 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, text, background, music=None): |
13 super(CutScene, self).__init__(game_state) | 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), | |
16 size=24, shadow='gray', wrap=True) | |
17 self.background = data.load_image('backgrounds/' + background) | 14 self.background = data.load_image('backgrounds/' + background) |
18 self.start_time = pygame.time.get_ticks() | 15 self.start_time = pygame.time.get_ticks() |
19 self.run_time = 60000 # ms | 16 self.run_time = 60000 # ms |
17 | |
20 self._background_music = None | 18 self._background_music = None |
21 if music and pygame.mixer.get_init(): | 19 if music and pygame.mixer.get_init(): |
22 self._background_music = data.filepath(music) | 20 self._background_music = data.filepath(music) |
21 | |
22 text_widget = Text(text, pygame.Rect(20, 20, 800-40, 600-40), | |
23 size=24, shadow='gray', wrap=True) | |
24 self.widgets.append(text_widget) | |
25 | |
26 button_set = ButtonSet() | |
27 button_set.append(TextButton("Continue", (300, 500), size=24, color='yellow')) | |
28 button_set.callbacks.append(self.done) | |
29 self.widgets.append(button_set) | |
30 | |
31 def done(self, selected=None, data=None): | |
32 # Avoid circular import... | |
33 from .menuscene import MenuScene | |
34 ChangeScene.post(MenuScene(self.game_state)) | |
23 | 35 |
24 def draw(self, surface, engine): | 36 def draw(self, surface, engine): |
25 viewport = surface.get_clip() | 37 viewport = surface.get_clip() |
26 | 38 |
27 # Scoll background back and forth: | 39 # Scoll background back and forth: |
32 if pos > max_pos: | 44 if pos > max_pos: |
33 pos = (2 * max_pos) - pos | 45 pos = (2 * max_pos) - pos |
34 surface.blit(self.background, viewport.topleft, | 46 surface.blit(self.background, viewport.topleft, |
35 pygame.Rect((pos, bottom), viewport.size)) | 47 pygame.Rect((pos, bottom), viewport.size)) |
36 | 48 |
37 self.text_widget.draw(surface) | |
38 super(CutScene, self).draw(surface, engine) | 49 super(CutScene, self).draw(surface, engine) |
39 | 50 |
40 def dispatch(self, ev): | 51 def dispatch(self, ev): |
41 if ev.type is KEYDOWN: | 52 if ev.type is KEYDOWN: |
42 if ev.key in(K_q, K_ESCAPE): | 53 if ev.key in(K_q, K_ESCAPE): |
43 # Avoid circular import... | 54 self.done() |
44 from .menuscene import MenuScene | |
45 ChangeScene.post(MenuScene(self.game_state)) | |
46 super(CutScene, self).dispatch(ev) | 55 super(CutScene, self).dispatch(ev) |
47 | 56 |
48 def enter(self): | 57 def enter(self): |
49 if self._background_music: | 58 if self._background_music: |
50 pygame.mixer.music.load(self._background_music) | 59 pygame.mixer.music.load(self._background_music) |