Move viewport from Engine to Scene.
authorSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 14:33:34 +0000 (16:33 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 14:33:34 +0000 (16:33 +0200)
koperkapel/scenes/base.py
koperkapel/scenes/credits.py
koperkapel/scenes/level.py
koperkapel/scenes/roach_management.py

index ade4d8bfddede638919ab9eb884423d38a9e55c6..26ee7819007dd06b132525175cb9fd2c84627193 100644 (file)
@@ -20,7 +20,6 @@ class Engine:
         self._app = app
         self._scene = scene
         self._world = world
-        self._viewport = (0, 0)
 
     def _apply_events(self, events):
         if not events:
@@ -41,19 +40,14 @@ class Engine:
         exit()
 
     def move_screen(self, offset):
-        self._viewport = (self._viewport[0] + offset[0],
-                          self._viewport[1] + offset[1])
-
-    def calc_offset(self, x, y):
-        """Return a position offset by the viewport"""
-        return x - self._viewport[0], y - self._viewport[1]
+        self._scene.move_screen(offset)
 
     @apply_events
     def update(self, dt):
         return self._scene.update(self._world.proxy(), self, dt)
 
     def draw(self):
-        self._scene.draw(self._app.screen, self._viewport)
+        self._scene.draw(self._app.screen)
 
     @apply_events
     def on_mouse_down(self, pos, button):
@@ -179,6 +173,15 @@ class Scene:
 
     def __init__(self):
         self.actors = Actors()
+        self.viewport = (0, 0)
+
+    def move_screen(self, offset):
+        self.viewport = (self.viewport[0] + offset[0],
+                         self.viewport[1] + offset[1])
+
+    def calc_offset(self, x, y):
+        """ Return a position offset by the viewport. """
+        return x - self.viewport[0], y - self.viewport[1]
 
     def enter(self, world):
         pass
@@ -189,7 +192,7 @@ class Scene:
     def update(self, world, engine, dt):
         pass
 
-    def draw(self, screen, viewport):
+    def draw(self, screen):
         screen.clear()
         self.actors.draw(screen)
 
index 3c1551c5281b0760f96746acba9b828d83081ba1..772943e51e57127cf9c8aa14e184e7b77b7a5df7 100644 (file)
@@ -7,7 +7,7 @@ from .base import Scene, ChangeSceneEvent
 class CreditsScene(Scene):
     """ Credits scene. """
 
-    def draw(self, screen, viewport):
+    def draw(self, screen):
         screen.clear()
         screen.draw.text("Credits", (300, 300))
 
index 0c57ae08d2c72614bdf03ec18e1d9cedc6640a2a..856f4cec8e9ead960cc666a1866d48fdd38363b1 100644 (file)
@@ -52,17 +52,18 @@ class BaseLevelScene(Scene):
     def update(self, world, engine, dt):
         """Fix the door and keypad positions"""
         for door in self._doors:
-            door.pos = engine.calc_offset(
+            door.pos = self.calc_offset(
                 door.game_pos[0] * TILE_SIZE, door.game_pos[1] * TILE_SIZE)
         for keypad in self._keypads:
-            keypad.pos = engine.calc_offset(
+            keypad.pos = self.calc_offset(
                 keypad.game_pos[0] * TILE_SIZE, keypad.game_pos[1] * TILE_SIZE)
 
-    def draw(self, screen, viewport):
+    def draw(self, screen):
         screen.clear()
         # 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
+        viewport = self.viewport
         screen.surface.blit(self._surfaces[self._level_layer], (0, 0),
                             area=(viewport[0], viewport[1], WIDTH, HEIGHT))
         if self._level_layer != 'floor':
index c0e82107a93ec56ed08059e8dba3a89bbaa56b3c..70af321ab4841b9fe3dc4af3a46db9c95d076937 100644 (file)
@@ -2,7 +2,9 @@
 
 from pgzero.constants import keys, mouse
 from pgzero.actor import Actor
+from pgzero.screen import Screen
 from ..actors.buttons import ImageButton
+from ..actors.surf import SurfActor
 from ..constants import WIDTH, HEIGHT
 from ..roaches import big_roaches, roach_by_name
 from ..serums import big_serums, roach_is_serumless, SERUMS
@@ -57,7 +59,15 @@ class RoachesScene(Scene):
 
     def _init_bg(self):
         self.actors.default.clear()
-        self.actors.default.add(self._vehicle.roach_management_overlay())
+        overlay = self._vehicle.roach_management_overlay()._surf
+        base = overlay.copy()
+        if self._level_scene is not None:
+            base.fill((0, 0, 0))
+            self._level_scene.draw(Screen(base))
+        else:
+            base.fill((10, 10, 10))
+        base.blit(overlay, (0, 0))
+        self.actors.default.add(SurfActor(base))
 
     def _init_seats(self):
         self._seat_layer.clear()