Mercurial > skaapsteker
view skaapsteker/menuscene.py @ 218:7ee5bd883d62
renamed first proper level
author | Adrianna Pińska <adrianna.pinska@gmail.com> |
---|---|
date | Thu, 07 Apr 2011 01:02:36 +0200 |
parents | aa154c4086cb |
children | 129afb4417cf |
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 = [ ('Temple', 'temple'), ('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 == 'resume': 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)) else: ChangeScene.post(LevelScene(self.game_state, data)) 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)