1 """ Main menu scene. """
3 from pgzero.constants import keys
4 from ..actors.buttons import TextButton
5 from ..actors.navigator import ActorNavigator
6 from .base import Scene, ChangeSceneEvent, QuitEvent
11 class MenuScene(Scene):
12 """ Main menu scene. """
16 self._title = self.actors.add(TextButton("Main Menu"))
17 self._title.pos = (300, 200)
18 self._nav = ActorNavigator()
20 TextButton("Play", action=self.change_to_level),
21 TextButton("Credits", action=self.change_to_credits),
22 TextButton("Quit", action=self.quit),
24 for i, item in enumerate(self._menu):
25 item.pos = (300, 300 + (i * 100))
28 self._menu, [keys.DOWN, keys.RIGHT], [keys.UP, keys.LEFT],
30 self._nav.current.select()
32 def change_to_level(self):
33 from .level import LevelScene
34 return [ChangeSceneEvent(LevelScene('level1'))]
36 def change_to_credits(self):
37 from .credits import CreditsScene
38 return [ChangeSceneEvent(CreditsScene())]
43 def on_key_down(self, key, mod, unicode):
44 if key == keys.RETURN:
45 current = self._nav.current
46 if current is not None:
47 return current.action()
49 prev, current = self._nav.follow(key)
52 if current is not None: