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, WorldEvent, QuitEvent
9 class MenuScene(Scene):
10 """ Main menu scene. """
14 self._title = self.actors.add(TextButton("Main Menu"))
15 self._title.pos = (300, 100)
16 self._nav = ActorNavigator()
18 TextButton("Play", action=self.change_to_level),
19 TextButton("View Last Generated Level",
20 action=self.change_to_viewer),
21 TextButton("Manage Roaches", action=self.change_to_roaches),
22 TextButton("Credits", action=self.change_to_credits),
23 TextButton("Quit", action=self.quit),
25 for i, item in enumerate(self._menu):
26 item.pos = (300, 200 + (i * 100))
29 self._menu, [keys.DOWN, keys.RIGHT], [keys.UP, keys.LEFT],
31 self._nav.current.select()
33 def change_to_level(self):
34 from .level import LevelScene
35 return [ChangeSceneEvent(LevelScene())]
37 def change_to_viewer(self):
38 from .viewlevel import ViewLevelScene
40 WorldEvent("set", {"level.name": "map"}),
41 ChangeSceneEvent(ViewLevelScene())
44 def change_to_roaches(self):
45 from .roaches import RoachesScene
46 return [ChangeSceneEvent(RoachesScene())]
48 def change_to_credits(self):
49 from .credits import CreditsScene
50 return [ChangeSceneEvent(CreditsScene())]
55 def on_key_down(self, key, mod, unicode):
56 if key == keys.RETURN:
57 current = self._nav.current
58 if current is not None:
59 return current.action()
61 prev, current = self._nav.follow(key)
64 if current is not None: