Changeset 375:8631e38afc24


Ignore:
Timestamp:
04/09/11 13:05:36 (12 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Phase:
public
Rebase:
38353239323834373264346236643331343738306263343866386132326666616564306434653264
Message:

Usage cutscene (with minor CutScene refactoring)

Location:
skaapsteker
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/cutscene.py

    r365 r375  
    88from . import data
    99from .engine import ChangeScene, Scene
     10from .levelscene import LevelScene
    1011from .widgets.text import Text, ButtonSet, TextButton, unindent_text
    1112
    1213class CutScene(Scene):
    13     def __init__(self, game_state, soundsystem, text, background, music=None):
     14    def __init__(self, game_state, soundsystem):
    1415        super(CutScene, self).__init__(game_state, soundsystem)
    15         self.background = data.load_image('backgrounds/' + background)
    16         fill = pygame.Surface(self.background.get_size(), flags=SRCALPHA)
     16        self._background_img = data.load_image('backgrounds/' + self.background)
     17        fill = pygame.Surface(self._background_img.get_size(), flags=SRCALPHA)
    1718        fill.fill((255, 255, 255, 128))
    18         self.background.convert_alpha(fill)
    19         self.background.blit(fill, (0, 0))
    20         self.background.convert_alpha()
    21         self.start_time = pygame.time.get_ticks()
    22         self.run_time = 60000 # ms
     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
    2324
    24         self._background_music = None
    25         self._background_music = music
     25        self._background_music = self.music
    2626
    27         text_widget = Text(text, pygame.Rect(20, 20,
    28                                              constants.SCREEN[0] - 40,
    29                                              constants.SCREEN[1] - 40),
     27        text_widget = Text(unindent_text(self.text),
     28                           pygame.Rect(20, 20,
     29                                       constants.SCREEN[0] - 40,
     30                                       constants.SCREEN[1] - 40),
    3031                           size=24, shadow='gray', wrap=True)
    3132        self.widgets.append(text_widget)
     
    4748
    4849        # Scoll background back and forth:
    49         max_pos = self.background.get_rect().width - viewport.width
    50         bottom = self.background.get_rect().height - viewport.height
    51         pos = ((pygame.time.get_ticks() - self.start_time)
    52                % (self.run_time * 2)) * max_pos // (self.run_time)
     50        max_pos = self._background_img.get_rect().width - viewport.width
     51        bottom = self._background_img.get_rect().height - viewport.height
     52        pos = ((pygame.time.get_ticks() - self._start_time)
     53               % (self._run_time * 2)) * max_pos // (self._run_time)
    5354        if pos > max_pos:
    5455            pos = (2 * max_pos) - pos
    55         surface.blit(self.background, viewport.topleft,
     56        surface.blit(self._background_img, viewport.topleft,
    5657                     pygame.Rect((pos, bottom), viewport.size))
    5758
     
    6970
    7071
    71 def opening_cutscene(game_state, soundsystem):
     72class OpeningCutScene(CutScene):
    7273    text = u"""
    7374    Many moons ago, an evil nine-tailed kitsune, a fearsome fox god, ruled the
     
    8687    The kitsune stole your tail. Now it’s time to get it back.
    8788    """
    88     text = unindent_text(text)
    89     return CutScene(game_state, soundsystem, text, 'background_01_back.png')
     89    background = 'background_01_back.png'
     90    music = None
     91
     92    def done(self, selected=None, data=None):
     93        ChangeScene.post(LevelScene(self.game_state, self._soundsystem,
     94                                    'temple.starting'))
     95
     96
     97class UsageCutScene(CutScene):
     98    text = u"""
     99    Arrow keys control your movement.
     100
     101    Double-tap ← or → to sprint,  ↑ to fly (when you can).
     102
     103    Z and X perform attacks.
     104    """
     105    background = 'background_01_back.png'
     106    music = None
  • skaapsteker/menuscene.py

    r274 r375  
    22from pygame.locals import K_ESCAPE, K_q, KEYDOWN, QUIT
    33
    4 from .cutscene import opening_cutscene
     4from .cutscene import OpeningCutScene, UsageCutScene
    55from .engine import ChangeScene, Scene
    66from .levelscene import LevelScene
     
    2525            ("Theatre", "theatre.starting"),
    2626            ("Celestial plane", "celestial_plane.starting"),
     27            ('Usage', 'usage'),
    2728            ('Quit', 'quit'),
    2829        ]
     
    3839            ChangeScene.post(self.cur_game)
    3940        elif data == 'cutscene':
    40             ChangeScene.post(opening_cutscene(self.game_state, self._soundsystem))
     41            ChangeScene.post(OpeningCutScene(self.game_state, self._soundsystem))
     42        elif data == 'usage':
     43            ChangeScene.post(UsageCutScene(self.game_state, self._soundsystem))
    4144        elif data == 'quit':
    4245            pygame.event.post(pygame.event.Event(QUIT))
Note: See TracChangeset for help on using the changeset viewer.