From 0a24cbb401a518f8c327e3a400014a0144f9fe7e Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 5 Mar 2016 13:38:33 +0200 Subject: [PATCH] Display seated and outside roaches. --- koperkapel/scenes/roach_management.py | 42 ++++++++++++++++++++------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/koperkapel/scenes/roach_management.py b/koperkapel/scenes/roach_management.py index cb939f8..21fc37c 100644 --- a/koperkapel/scenes/roach_management.py +++ b/koperkapel/scenes/roach_management.py @@ -17,6 +17,7 @@ VEHICLE_MID_X = WIDTH * 3 // 8 VEHICLE_MID_Y = HEIGHT * 1 // 2 BUTTON_INSET = (20, 20) SERUM_OFFSET = (0, 20) +ROACH_PAD_OFFSET = (0, 20) def inset_button(pos, d): @@ -31,7 +32,8 @@ class RoachesScene(Scene): def __init__(self): super().__init__() self._vehicle = None - self._seat_pos = None + self._seat_pos = 0 + self._outside_roach = None self._outside_roach_pos = 0 self._inventory_pos = 0 self._inventory_item = None @@ -45,10 +47,10 @@ class RoachesScene(Scene): self._init_serums() def enter(self, world): - self._vehicle = Vehicle.by_type(world.vehicles.current) + self._vehicle = Vehicle.current(world) self._init_bg() self._init_seats() - self._init_roaches(world.roaches) + self._init_roaches(world) self._update_inventory(world) def _init_bg(self): @@ -63,13 +65,10 @@ class RoachesScene(Scene): seat.vehicle_pos[0] + VEHICLE_MID_X, seat.vehicle_pos[1] + VEHICLE_MID_Y) - def _init_roaches(self, roaches): - self._roach_layer.clear() - for i, roach in enumerate(roaches): - roach_actor = self._roach_layer.add(big_roaches.assemble(roach)) - # TODO: less hacky seat assignment - if i < len(self._seat_layer): - roach_actor.pos = self._seat_layer[i].pos + def _init_roaches(self, world): + self._roach_actors = {} + for roach in world.roaches: + self._roach_actors[roach.name] = big_roaches.assemble(roach) def _init_serums(self): self._serum_actors = { @@ -88,6 +87,28 @@ class RoachesScene(Scene): inv_pad_centre[1] + SERUM_OFFSET[1]) self._inventory_layer.add(serum_actor) + def _update_roaches(self, world): + self._roach_layer.clear() + seating = self._vehicle.seating(world) + outside_roaches = [] + for roach in world.roaches: + seat_pos = seating.get(roach.name) + if seat_pos is not None: + roach_actor = self._roach_actors[roach.name] + roach_actor.pos = self._seat_layer[seat_pos].pos + self._roach_layer.add(roach_actor) + else: + outside_roaches.append(roach.name) + self._outside_roach_pos %= len(outside_roaches) + if outside_roaches: + roach_actor = self._roach_actors[ + outside_roaches[self._outside_roach_pos]] + roach_pad_center = self._roach_pad.center + roach_actor.pos = ( + roach_pad_center[0] + ROACH_PAD_OFFSET[0], + roach_pad_center[1] + ROACH_PAD_OFFSET[1]) + self._roach_layer.add(roach_actor) + def _init_pads(self): self._roach_pad = self._pad_layer.add( Actor("roach_management/roach_pad", anchor=("left", "bottom"))) @@ -141,6 +162,7 @@ class RoachesScene(Scene): def update(self, world, dt): self._update_inventory(world) + self._update_roaches(world) def on_key_down(self, key, mod, unicode): if key == keys.ESCAPE: -- 2.34.1