Center display around our hero(es)
authorNeil <neil@dip.sun.ac.za>
Sat, 5 Mar 2016 06:23:12 +0000 (08:23 +0200)
committerNeil <neil@dip.sun.ac.za>
Sat, 5 Mar 2016 06:23:12 +0000 (08:23 +0200)
koperkapel/scenes/level.py

index a800ba0d842d0f5c3d130b16acbef92f6c0aa958..9dd8b61e3d7958ab67f7f25ae62b9467de770c7a 100644 (file)
@@ -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)