Hook up a 'view level' scene to display most recently generated map
authorNeil <neil@dip.sun.ac.za>
Tue, 1 Mar 2016 09:35:04 +0000 (11:35 +0200)
committerNeil <neil@dip.sun.ac.za>
Tue, 1 Mar 2016 09:35:04 +0000 (11:35 +0200)
koperkapel/scenes/menu.py
koperkapel/scenes/viewlevel.py [new file with mode: 0644]

index 39ab12c1ff1e1615edc25dc191ce007ff84f97c7..c91c14213e99ae00226065d17129d96be90f1e55 100644 (file)
@@ -18,6 +18,8 @@ class MenuScene(Scene):
         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),
         ]
@@ -33,6 +35,10 @@ class MenuScene(Scene):
         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())]
diff --git a/koperkapel/scenes/viewlevel.py b/koperkapel/scenes/viewlevel.py
new file mode 100644 (file)
index 0000000..8a101df
--- /dev/null
@@ -0,0 +1,31 @@
+"""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)