5 import pygame.locals as pgl
7 from naja.constants import KEYS, PALETTE, KONAMI_CODE
8 from naja.events import SceneChangeEvent, QuitGameEvent
9 from naja.options import options
10 from naja.scenes.scene import Scene
11 from naja.scenes.credits import CreditsScene
12 from naja.scenes.game import GameScene
13 from naja.scenes.howto import HowtoScene
14 from naja.scenes.load_save import LoadGameScene, SaveGameScene
15 from naja.scenes.new_game import NewGameScene
16 from naja.scenes.puzzlelist import PuzzleListScene
17 from naja.widgets.selector import SelectorWidget
18 from naja.widgets.text import TextWidget
19 from naja.widgets.image_box import ImageBox
20 from naja.sound import sound
23 class MenuScene(Scene):
24 def __init__(self, state):
25 super(MenuScene, self).__init__(state)
27 background = ImageBox(
28 (0, 0), "screens/splash.png")
31 selector = SelectorWidget()
33 y_offset, y_diff = 270, 36
38 (x_offset, y_offset), 'Resume Game', colour=PALETTE.WHITE,
39 unselectable_colour=PALETTE.GREY, centre=True)
40 resume.add_callback('click', self.scene_callback(GameScene))
41 resume.set_selectable_callback(lambda: state is not None)
46 (x_offset, y_offset), 'New Random Game', colour=PALETTE.WHITE,
48 new.add_callback('click', self.scene_callback(NewGameScene))
53 (x_offset, y_offset), 'New Puzzle', colour=PALETTE.WHITE,
55 new.add_callback('click', self.scene_callback(PuzzleListScene))
60 (x_offset, y_offset), 'Load Game', colour=PALETTE.WHITE,
62 load.add_callback('click', self.scene_callback(LoadGameScene))
67 (x_offset, y_offset), 'Save Game', colour=PALETTE.WHITE,
68 unselectable_colour=PALETTE.GREY, centre=True)
69 save.add_callback('click', self.scene_callback(SaveGameScene))
70 save.set_selectable_callback(lambda: state is not None)
75 (x_offset, y_offset), 'How To Play', colour=PALETTE.WHITE,
77 howto.add_callback('click', self.scene_callback(HowtoScene))
82 (x_offset, y_offset), 'Credits', colour=PALETTE.WHITE,
84 credits.add_callback('click', self.scene_callback(CreditsScene))
88 quit = TextWidget((x_offset, y_offset), 'Quit', colour=PALETTE.WHITE,
90 quit.add_callback('click', lambda event: QuitGameEvent.post())
94 if not sound.playing_music:
95 sound.play_music('scape.ogg', 0.25)
97 def scene_callback(self, scene_class):
98 return lambda event: SceneChangeEvent.post(scene_class)
100 def handle_event(self, ev):
101 if ev.type == pgl.KEYDOWN and self.konami is not None:
102 if ev.key in KEYS.KONAMI:
103 self.konami.append(ev.key)
104 if self.konami == KONAMI_CODE:
105 options['cheat_enabled'] = True
106 print "Cheats enabled."
107 print " Try hitting some number keys."
109 elif self.konami != KONAMI_CODE[:len(self.konami)]:
111 return super(MenuScene, self).handle_event(ev)
113 def handle_scene_event(self, ev):
114 if ev.type == pgl.KEYDOWN:
115 if ev.key in KEYS.QUIT: