1 """ Main menu scene. """
3 from pgzero.constants import keys
4 from pgzero.loaders import images
5 from ..actors.navigator import ActorNavigator
6 from ..actors.orientatedsurf import OrientatedSurfActor, SelectableSurfActor
7 from ..util import safepath
8 from .base import Scene, ChangeSceneEvent, WorldEvent, QuitEvent
11 class MenuScene(Scene):
12 """ Main menu scene. """
16 self.actors.add_layer("buttons", level=10)
21 self.actors.default.clear()
22 self.actors.default.add(OrientatedSurfActor(
23 images.load(safepath("splash/background"))))
25 def _init_buttons(self):
26 self._nav = ActorNavigator()
28 self._build_button("new_game", action=self.change_to_new_game),
29 self._build_button("resume_game", action=self.change_to_resume),
30 self._build_button("credits", action=self.change_to_credits),
31 self._build_button("quit", action=self.quit),
33 for i, item in enumerate(menu):
34 item.pos = (675, 275 + (i * 100))
37 menu, [keys.DOWN, keys.RIGHT], [keys.UP, keys.LEFT],
39 self._nav.current.selected = True
41 def _build_button(self, name, action):
42 actor = SelectableSurfActor(
43 images.load(safepath("splash/%s" % (name,))),
44 images.load(safepath("splash/%s_selected" % (name,))))
48 def change_to_resume(self):
49 from .level import GameLevelScene
50 return [ChangeSceneEvent(GameLevelScene())]
52 def change_to_new_game(self):
53 from .level import GameLevelScene
56 ChangeSceneEvent(GameLevelScene())
59 def change_to_credits(self):
60 from .credits import CreditsScene
61 return [ChangeSceneEvent(CreditsScene())]
66 def on_key_down(self, key, mod, unicode):
67 if key == keys.RETURN:
68 current = self._nav.current
69 if current is not None:
70 return current.action()
72 prev, current = self._nav.follow(key)
75 if current is not None:
76 current.selected = True