X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=koperkapel%2Fscenes%2Froach_management.py;h=9a356ac918c9f8932b49e135b85abd0262fac4ea;hb=dda49d4fadc602bd8bc87137124843994e4c4e36;hp=d5fc67ffe749bcb3039778b2f7142e29c96d47ec;hpb=55c4bcf03552816d8da08974179aac95b40996af;p=koperkapel.git diff --git a/koperkapel/scenes/roach_management.py b/koperkapel/scenes/roach_management.py index d5fc67f..9a356ac 100644 --- a/koperkapel/scenes/roach_management.py +++ b/koperkapel/scenes/roach_management.py @@ -4,8 +4,8 @@ from pgzero.constants import keys, mouse 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, SERUMS +from ..roaches import big_roaches, roach_by_name +from ..serums import big_serums, roach_is_serumless, SERUMS from ..vehicles.base import Vehicle from .base import Scene, ChangeSceneEvent @@ -184,11 +184,32 @@ class RoachesScene(Scene): if world is None: self._update_calls.append(self._click_inventory_pad) return + roach_name = self._vehicle.roach_at(world, self._seat_pos) + if roach_name is None: + return + roach = roach_by_name(world, roach_name) + if roach is None: + return + serums = list(world.serums) + if self._inventory_pos >= len(serums): + return + serum = serums.pop(self._inventory_pos) + if roach_is_serumless(roach): + roach[serum] = True + world.serums = serums + self._update_calls.append((self._update_roach_actor, roach_name)) + + def _update_roach_actor(self, world, roach_name): + roach = roach_by_name(world, roach_name) + self._roach_actors[roach_name] = big_roaches.assemble(roach) def update(self, world, engine, dt): - while self._update_calls: - f = self._update_calls.pop() - f(world) + update_calls, self._update_calls = self._update_calls, [] + while update_calls: + f, args = update_calls.pop(), () + if type(f) is tuple: + f, args = f[0], f[1:] + f(world, *args) events = world.pop_events() self._update_inventory(world) self._update_roaches(world)