From: Simon Cross Date: Sat, 5 Mar 2016 14:33:34 +0000 (+0200) Subject: Move viewport from Engine to Scene. X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=8ed75cacf6664d0018859c9c84e99554c08ab801;p=koperkapel.git Move viewport from Engine to Scene. --- diff --git a/koperkapel/scenes/base.py b/koperkapel/scenes/base.py index ade4d8b..26ee781 100644 --- a/koperkapel/scenes/base.py +++ b/koperkapel/scenes/base.py @@ -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) diff --git a/koperkapel/scenes/credits.py b/koperkapel/scenes/credits.py index 3c1551c..772943e 100644 --- a/koperkapel/scenes/credits.py +++ b/koperkapel/scenes/credits.py @@ -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)) diff --git a/koperkapel/scenes/level.py b/koperkapel/scenes/level.py index 0c57ae0..856f4ce 100644 --- a/koperkapel/scenes/level.py +++ b/koperkapel/scenes/level.py @@ -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': diff --git a/koperkapel/scenes/roach_management.py b/koperkapel/scenes/roach_management.py index c0e8210..70af321 100644 --- a/koperkapel/scenes/roach_management.py +++ b/koperkapel/scenes/roach_management.py @@ -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()