Mercurial > skaapsteker
view skaapsteker/menuscene.py @ 454:95527fd29872
More complete game load/save/restart.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sat, 09 Apr 2011 20:47:35 +0200 |
parents | fada4195349d |
children | fb9258d66137 |
line wrap: on
line source
import pygame from pygame.locals import K_ESCAPE, K_q, KEYDOWN, QUIT from .cutscene import OpeningCutScene, UsageCutScene, CreditsCutScene from .engine import ChangeScene, Scene, NewGameEvent from .levelscene import LevelScene from .widgets.text import Text, TextChoice class MenuScene(Scene): def __init__(self, game_state, soundsystem): super(MenuScene, self).__init__(game_state, soundsystem) self.widgets.append(Text("MENU:", (50, 50), color='white', size=48)) menu_options = [ ('Start new game', 'restart'), ('Starting Cutscene', 'cutscene'), ('Temple', 'temple.starting'), ("Temple grounds", "temple_grounds.starting"), ("Road", "road.starting"), ("Town", "town.starting"), ("Tea house", "tea_house.starting"), ("Kumiko's rooms", "geisha_room.starting"), ("Market", "market.starting"), ("Fishmonger's house", "fishmonger_house.starting"), ("Theatre", "theatre.starting"), ("Celestial plane", "celestial_plane.starting"), ('Usage', 'usage'), ('Credits', 'credits'), ('Quit', 'quit'), ] if self.game_state.world 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 resume_game(self): fox = self.game_state.world.fox ChangeScene.post((LevelScene, '.'.join([fox.level, fox.doorway]))) def selected(self, option, data): "Callback from menu TextChoice" if data == 'resume': self.resume_game() elif data == 'restart': NewGameEvent.post(LevelScene) elif data == 'cutscene': ChangeScene.post(OpeningCutScene(self.game_state, self._soundsystem)) elif data == 'usage': ChangeScene.post(UsageCutScene(self.game_state, self._soundsystem)) elif data == 'credits': ChangeScene.post(CreditsCutScene(self.game_state, self._soundsystem)) elif data == 'quit': pygame.event.post(pygame.event.Event(QUIT)) else: ChangeScene.post(LevelScene(self.game_state, self._soundsystem, 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)