Mercurial > skaapsteker
view skaapsteker/cutscene.py @ 575:c252e20e1c1b
Document down key
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Sun, 10 Apr 2011 10:06:38 +0200 |
parents | e648501c2eea |
children | 0dfb62814de6 |
line wrap: on
line source
# -*- coding: utf-8 -*- from __future__ import division import pygame from pygame.locals import K_ESCAPE, K_q, KEYDOWN, SRCALPHA from . import constants from . import data from .engine import ChangeScene, Scene from .levelscene import LevelScene from .widgets.text import Text, ButtonSet, TextButton, unindent_text class CutScene(Scene): def __init__(self, game_state, soundsystem): super(CutScene, self).__init__(game_state, soundsystem) self._background_music = self.music button_set = ButtonSet() # TODO: Dynamic position button_set.append(TextButton("Continue", (20, constants.SCREEN[1] - 68), size=24, color='red')) button_set.callbacks.append(self.done) self.widgets.append(button_set) def done(self, selected=None, data=None): # Avoid circular import... from .menuscene import MenuScene ChangeScene.post((MenuScene,)) def dispatch(self, ev): if ev.type is KEYDOWN: if ev.key in(K_q, K_ESCAPE): self.done() super(CutScene, self).dispatch(ev) def enter(self): if self._background_music and self._soundsystem: self._soundsystem.play_background_music(self._background_music) class TextCutScene(CutScene): wrap = True def __init__(self, game_state, soundsystem): super(TextCutScene, self).__init__(game_state, soundsystem) self._background_img = data.load_image('backgrounds/' + self.background) fill = pygame.Surface(self._background_img.get_size(), flags=SRCALPHA) fill.fill((255, 255, 255, 128)) self._background_img.convert_alpha(fill) self._background_img.blit(fill, (0, 0)) self._background_img.convert_alpha() self._start_time = pygame.time.get_ticks() self._run_time = 60000 # ms text_widget = Text(unindent_text(self.text), pygame.Rect(20, 20, constants.SCREEN[0] - 40, constants.SCREEN[1] - 40), size=24, shadow='gray', wrap=self.wrap) self.widgets.append(text_widget) def draw(self, surface, engine): viewport = surface.get_clip() # Scoll background back and forth: max_pos = self._background_img.get_rect().width - viewport.width bottom = self._background_img.get_rect().height - viewport.height pos = ((pygame.time.get_ticks() - self._start_time) % (self._run_time * 2)) * max_pos // (self._run_time) if pos > max_pos: pos = (2 * max_pos) - pos surface.blit(self._background_img, viewport.topleft, pygame.Rect((pos, bottom), viewport.size)) super(TextCutScene, self).draw(surface, engine) class OpeningCutScene(TextCutScene): text = u""" Many moons ago, an evil nine-tailed kitsune, a fearsome fox god, ruled the land. It had many powers — the ability to shape shift, turn invisible, control the elements. Its powers came from its majestic tails and the kitsune guarded them ferociously. If any fox attained eight tails, it would battle the kitsune for domination of the celestial world. To prevent this, the kitsune stole the tails of all the foxes it encountered. The evil kitsune challenged every fox to a haiku contest. But the competition was not fair, and the kitsune cheated every time. When it defeated the poor fox, it stole its tail and threw it to the four winds. The kitsune stole your tail. Now it’s time to get it back. """ background = 'background_01_back.png' music = 'music/ambient japanese music 2.ogg' def done(self, selected=None, data=None): fox = self.game_state.world.fox ChangeScene.post((LevelScene, '.'.join([fox.level, fox.doorway]))) class UsageCutScene(TextCutScene): wrap = False text = u""" Arrow keys control your movement. Double-tap ← or → to sprint Z and X to perform attacks. ↓ to pick up / drops items or perform actions. With the right tails, you can do the following: C to shift shape. V to make you invisible. Double-tap ↑ to fly. Dvorak users: Pass the --dvorak command-line argument """ background = 'background_02_back.png' music = None class CreditsCutScene(TextCutScene): text = u""" Credits: Programmers: Adrianna Pińska, Jeremy Thurgood, Neil Muller, Simon Cross, Stefano Rivera Art: Oliver Hambsch Story: Anna Malczyk Music & Sound Effects: OLPC Sound Library: Richard Boulanger; The Free Sound Project: Connor Purcell, Nathan Hill, Donnie Thompson, Muki, Tom Potter, Kayden Riggs, ITE, GRSites.com, dobroide, pauliep83, nextmaking, aesqe, inferno """ background = 'background_03_back.png' music = 'music/ambient japanese music 3.ogg' class VictoryCutScene(CutScene): music = 'music/ambient japanese music 1.ogg' def __init__(self, game_state, soundsystem): super(VictoryCutScene, self).__init__(game_state, soundsystem) self._background_img = data.load_image('backgrounds/victory-menu.png') def draw(self, surface, engine): surface.blit(self._background_img, (0, 0)) super(VictoryCutScene, self).draw(surface, engine)