Split level scene for game play extensions
authorNeil <neil@dip.sun.ac.za>
Thu, 3 Mar 2016 21:16:03 +0000 (23:16 +0200)
committerNeil <neil@dip.sun.ac.za>
Thu, 3 Mar 2016 21:16:03 +0000 (23:16 +0200)
koperkapel/scenes/level.py
koperkapel/scenes/menu.py
koperkapel/scenes/viewlevel.py

index 37f554012e7500db17585a88a0c27f6d13beac70..9a8fdc36957459a8fcc80465912c1330f5ec46ec 100644 (file)
@@ -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
index eefd5515fc5cf6e51daadc13548c2cf920b41424..ce09cb5ccb2afa8b9505affb6b7b02172ba12db5 100644 (file)
@@ -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
index 092506721c7aee654c63dd869d502d202898397c..fa3fd997d4a5843bd7b7578434457190738b076e 100644 (file)
@@ -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):