From d8e680f0570eaee2debe5109532c23a6457035f0 Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 3 Mar 2016 23:16:03 +0200 Subject: [PATCH] Split level scene for game play extensions --- koperkapel/scenes/level.py | 26 ++++++++++++-------------- koperkapel/scenes/menu.py | 4 ++-- koperkapel/scenes/viewlevel.py | 4 ++-- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/koperkapel/scenes/level.py b/koperkapel/scenes/level.py index 37f5540..9a8fdc3 100644 --- a/koperkapel/scenes/level.py +++ b/koperkapel/scenes/level.py @@ -5,10 +5,10 @@ from pygame import Surface import pygame.locals as pgl from ..loaders.levelloader import levels from .base import Scene, ChangeSceneEvent -from ..constants import TILE_SIZE +from ..constants import TILE_SIZE, WIDTH, HEIGHT -class LevelScene(Scene): +class BaseLevelScene(Scene): """ Level scene. """ def enter(self, world): @@ -42,20 +42,18 @@ class LevelScene(Scene): # Viewport is the position of the screen relative to the # surface. We need the position of the surface relative to # the screen for the blit, so this conversion - screen_pos = -viewport[0], -viewport[1] - if self._level_layer == 'floor': - screen.blit(self._surfaces[self._level_layer], screen_pos) - else: - # blit tunnels, with translucent overlay - # We need to call pygame.Surface.blit ourselves, - # since pgzero's screen blit hides the blend flags - # from us - tunnels = self._surfaces[self._level_layer].copy() - tunnels.blit(self._overlay, (0, 0), - special_flags=pgl.BLEND_MULT) - screen.blit(tunnels, screen_pos) + screen.surface.blit(self._surfaces[self._level_layer], (0, 0), + area=(viewport[0], viewport[1], WIDTH, HEIGHT)) + if self._level_layer != 'floor': + screen.surface.blit(self._overlay, (0, 0), + area=(viewport[0], viewport[1], WIDTH, HEIGHT), + special_flags=pgl.BLEND_ADD) def on_key_down(self, key, mod, unicode): if key == keys.ESCAPE: from .menu import MenuScene return [ChangeSceneEvent(MenuScene())] + + +class GameLevelScene(BaseLevelScene): + pass diff --git a/koperkapel/scenes/menu.py b/koperkapel/scenes/menu.py index eefd551..ce09cb5 100644 --- a/koperkapel/scenes/menu.py +++ b/koperkapel/scenes/menu.py @@ -31,8 +31,8 @@ class MenuScene(Scene): self._nav.current.select() def change_to_level(self): - from .level import LevelScene - return [ChangeSceneEvent(LevelScene())] + from .level import GameLevelScene + return [ChangeSceneEvent(GameLevelScene())] def change_to_viewer(self): from .viewlevel import ViewLevelScene diff --git a/koperkapel/scenes/viewlevel.py b/koperkapel/scenes/viewlevel.py index 0925067..fa3fd99 100644 --- a/koperkapel/scenes/viewlevel.py +++ b/koperkapel/scenes/viewlevel.py @@ -1,12 +1,12 @@ """Render a level and allow moving the scene""" from pgzero.constants import keys -from .level import LevelScene +from .level import BaseLevelScene from .base import MoveViewportEvent from ..constants import TILE_SIZE -class ViewLevelScene(LevelScene): +class ViewLevelScene(BaseLevelScene): """ Level scene. """ def on_key_down(self, key, mod, unicode): -- 2.34.1