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.introduction import IntroductionScene
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), 'Introduction', colour=PALETTE.WHITE,
40 intro.add_callback('click', self.scene_callback(IntroductionScene))
45 (x_offset, y_offset), 'Resume Game', colour=PALETTE.WHITE,
46 unselectable_colour=PALETTE.GREY, centre=True)
47 resume.add_callback('click', self.scene_callback(GameScene))
48 resume.set_selectable_callback(lambda: state is not None)
58 (x_offset, y_offset), 'New Random Game', colour=PALETTE.WHITE,
60 new.add_callback('click', self.scene_callback(NewGameScene))
65 (x_offset, y_offset), 'New Puzzle', colour=PALETTE.WHITE,
67 new.add_callback('click', self.scene_callback(PuzzleListScene))
72 (x_offset, y_offset), 'Load Game', colour=PALETTE.WHITE,
74 load.add_callback('click', self.scene_callback(LoadGameScene))
79 (x_offset, y_offset), 'Save Game', colour=PALETTE.WHITE,
80 unselectable_colour=PALETTE.GREY, centre=True)
81 save.add_callback('click', self.scene_callback(SaveGameScene))
82 save.set_selectable_callback(lambda: state is not None)
87 (x_offset, y_offset), 'Credits', colour=PALETTE.WHITE,
89 credits.add_callback('click', self.scene_callback(CreditsScene))
93 quit = TextWidget((x_offset, y_offset), 'Quit', colour=PALETTE.WHITE,
95 quit.add_callback('click', lambda event: QuitGameEvent.post())
99 if not sound.playing_music:
100 sound.play_music('scape.ogg', 0.25)
102 def scene_callback(self, scene_class):
103 return lambda event: SceneChangeEvent.post(scene_class)
105 def handle_event(self, ev):
106 if ev.type == pgl.KEYDOWN and self.konami is not None:
107 if ev.key in KEYS.KONAMI:
108 self.konami.append(ev.key)
109 if self.konami == KONAMI_CODE:
110 options['cheat_enabled'] = True
111 print "Cheats enabled."
112 print " Try hitting some number keys."
114 elif self.konami != KONAMI_CODE[:len(self.konami)]:
116 return super(MenuScene, self).handle_event(ev)
118 def handle_scene_event(self, ev):
119 if ev.type == pgl.KEYDOWN:
120 if ev.key in KEYS.QUIT: