Mercurial > skaapsteker
view skaapsteker/menuscene.py @ 134:4713a2a3b0be
Initial cutscene screen
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Tue, 05 Apr 2011 00:06:07 +0200 |
parents | aca8b7456c72 |
children | 8d45715c587d |
line wrap: on
line source
import pygame from pygame.locals import K_ESCAPE, K_q, KEYDOWN, QUIT from .cutscene import opening_cutscene from .engine import ChangeScene, Scene from .levelscene import LevelScene from .widgets.text import Text, TextChoice class MenuScene(Scene): def __init__(self, game_state, cur_game=None): super(MenuScene, self).__init__(game_state) self.widgets.append(Text("MENU:", (50, 50), color='white', size=48)) self.cur_game = cur_game menu_options = [ ('Level 1', 'level1'), ('Level 2', 'level2'), ('Level 3', 'level3'), ('Level 4', 'level4'), ('Level 5', 'level5'), ('Starting Cutscene', 'cutscene'), ('Quit', 'quit'), ] if cur_game is not None: menu_options.insert(0, ('Resume Game', 'resume')) self.choice = TextChoice(menu_options, (50, 100), color='white') self.choice.callbacks.append(self.selected) self.widgets.append(self.choice) def selected(self, option, data): "Callback from menu TextChoice" if data.startswith('level'): ChangeScene.post(LevelScene(self._game_state, data)) elif data == 'resume': self.cur_game.thaw() ChangeScene.post(self.cur_game) elif data == 'cutscene': ChangeScene.post(opening_cutscene(self._game_state)) elif data == 'quit': pygame.event.post(pygame.event.Event(QUIT)) def draw(self, surface, engine): surface.fill(pygame.Color('black')) super(MenuScene, self).draw(surface, engine) def dispatch(self, ev): if ev.type is KEYDOWN: if ev.key in(K_q, K_ESCAPE): pygame.event.post(pygame.event.Event(QUIT)) super(MenuScene, self).dispatch(ev)