From: Simon Cross Date: Fri, 4 Mar 2016 22:58:03 +0000 (+0200) Subject: Clean up inventory displaying. X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=0f2d2e9c4d31d58d0c0cfe1eb7327ce430a61dbd;p=koperkapel.git Clean up inventory displaying. --- diff --git a/koperkapel/scenes/roach_management.py b/koperkapel/scenes/roach_management.py index e206e10..3ed1ab0 100644 --- a/koperkapel/scenes/roach_management.py +++ b/koperkapel/scenes/roach_management.py @@ -5,7 +5,7 @@ from pgzero.actor import Actor from ..actors.buttons import ImageButton from ..constants import WIDTH, HEIGHT from ..roaches import big_roaches -from ..serums import big_serums +from ..serums import big_serums, SERUMS from ..vehicles.base import Vehicle from .base import Scene, ChangeSceneEvent @@ -32,20 +32,22 @@ class RoachesScene(Scene): super().__init__() self._outside_roach_pos = 0 self._inventory_pos = 0 + self._inventory_item = None self._roaches = self.actors.add_layer("roaches", level=10) - self._serums = self.actors.add_layer("serums", level=10) + self._inventory = self.actors.add_layer("inventory", level=10) self._pads = self.actors.add_layer("pads", level=5) self._seats = self.actors.add_layer("seats", level=5) self._buttons = self.actors.add_layer("buttons", level=6) self._init_pads() self._init_buttons() + self._init_serums() def enter(self, world): self._vehicle = Vehicle.by_type(world.vehicles.current) self._init_bg() self._init_seats() self._init_roaches(world.roaches) - self._update_serums(world.serums) + self._update_inventory(world) def _init_bg(self): self.actors.default.add(self._vehicle.background) @@ -65,17 +67,22 @@ class RoachesScene(Scene): if i < len(self._seats): roach_actor.pos = self._seats[i].pos - def _update_serums(self, serums): - self._serums.clear() + def _init_serums(self): + self._serum_actors = { + serum: big_serums.assemble(serum) for serum in SERUMS} + + def _update_inventory(self, world): + self._inventory.clear() + serums = world.serums if not serums: return self._inventory_pos %= len(serums) - serum_actor = self._serums.add( - big_serums.assemble(serums[self._inventory_pos])) + serum_actor = self._serum_actors[serums[self._inventory_pos]] inv_pad_centre = self._inventory_pad.center serum_actor.pos = ( inv_pad_centre[0] + SERUM_OFFSET[0], inv_pad_centre[1] + SERUM_OFFSET[1]) + self._inventory.add(serum_actor) def _init_pads(self): self._roach_pad = self._pads.add( @@ -128,7 +135,7 @@ class RoachesScene(Scene): print("Eject roach.") def update(self, world, dt): - self._update_serums(world.serums) + self._update_inventory(world) def on_key_down(self, key, mod, unicode): if key == keys.ESCAPE: