From 86092c002ef88ab0eb450cc7d16c2437f7861729 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 1 Mar 2016 11:35:04 +0200 Subject: [PATCH] Hook up a 'view level' scene to display most recently generated map --- koperkapel/scenes/menu.py | 6 ++++++ koperkapel/scenes/viewlevel.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 koperkapel/scenes/viewlevel.py diff --git a/koperkapel/scenes/menu.py b/koperkapel/scenes/menu.py index 39ab12c..c91c142 100644 --- a/koperkapel/scenes/menu.py +++ b/koperkapel/scenes/menu.py @@ -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 index 0000000..8a101df --- /dev/null +++ b/koperkapel/scenes/viewlevel.py @@ -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) -- 2.34.1