From 8dadf9accd2b841312131667c69f4a801fb93782 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 5 Mar 2016 08:23:12 +0200 Subject: [PATCH] Center display around our hero(es) --- koperkapel/scenes/level.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/koperkapel/scenes/level.py b/koperkapel/scenes/level.py index a800ba0..9dd8b61 100644 --- a/koperkapel/scenes/level.py +++ b/koperkapel/scenes/level.py @@ -62,16 +62,18 @@ class GameLevelScene(BaseLevelScene): def enter(self, world): super().enter(world) self._roaches = self.actors.add_layer("roaches", level=10) - self._init_roaches(world.roaches) + return self._init_roaches(world.roaches) def _init_roaches(self, roaches): - x, y = self._level.start_pos for roach in roaches: roach_actor = self._roaches.add(default_roaches.assemble(roach)) roach_actor.anchor = (0, 0) - roach_actor.pos = (x * TILE_SIZE, y * TILE_SIZE) + roach_actor.pos = (WIDTH // 2, HEIGHT // 2) + x, y = self._level.start_pos self._set_pos(x, y) self._level_layer = 'floor' + # Fix viewport offset + return [MoveViewportEvent((x * TILE_SIZE - WIDTH // 2, y * TILE_SIZE - HEIGHT // 2))] def _set_pos(self, x, y): self._player_pos = (x, y) -- 2.34.1