self._nav = ActorNavigator()
self._menu = [
TextButton("Play", action=self.change_to_level),
+ TextButton("View Last Generated Level",
+ action=self.change_to_viewer),
TextButton("Credits", action=self.change_to_credits),
TextButton("Quit", action=self.quit),
]
from .level import LevelScene
return [ChangeSceneEvent(LevelScene('level1'))]
+ def change_to_viewer(self):
+ from .viewlevel import ViewLevelScene
+ return [ChangeSceneEvent(ViewLevelScene('map'))]
+
def change_to_credits(self):
from .credits import CreditsScene
return [ChangeSceneEvent(CreditsScene())]
--- /dev/null
+"""Render a level and allow moving the scene"""
+
+from pgzero.constants import keys
+from .level import LevelScene
+from ..constants import TILE_SIZE
+
+
+class ViewLevelScene(LevelScene):
+ """ Level scene. """
+
+ def __init__(self, level_name):
+ super(ViewLevelScene, self).__init__(level_name)
+ self._pos = (0, 0)
+
+ def draw(self, screen):
+ super(ViewLevelScene, self).draw(screen, self._pos)
+
+ def on_key_down(self, key, mod, unicode):
+ if key == keys.DOWN:
+ self._pos = self._pos[0], self._pos[1] + TILE_SIZE
+ return
+ elif key == keys.UP:
+ self._pos = self._pos[0], self._pos[1] - TILE_SIZE
+ return
+ elif key == keys.LEFT:
+ self._pos = self._pos[0] - TILE_SIZE, self._pos[1]
+ return
+ elif key == keys.RIGHT:
+ self._pos = self._pos[0] + TILE_SIZE, self._pos[1]
+ return
+ return super(ViewLevelScene, self).on_key_down(key, mod, unicode)