From 00e091bb055bfa240d89cb24500a706327faf81e Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 5 Mar 2016 00:43:07 +0200 Subject: [PATCH] Cycle through serums. --- koperkapel/scenes/roach_management.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/koperkapel/scenes/roach_management.py b/koperkapel/scenes/roach_management.py index 935b3cb..f960a5e 100644 --- a/koperkapel/scenes/roach_management.py +++ b/koperkapel/scenes/roach_management.py @@ -2,9 +2,10 @@ from pgzero.constants import keys, mouse from pgzero.actor import Actor -from ..actors.buttons import TextButton, ImageButton +from ..actors.buttons import ImageButton from ..constants import WIDTH, HEIGHT from ..roaches import big_roaches +from ..serums import big_serums from ..vehicles.base import Vehicle from .base import Scene, ChangeSceneEvent @@ -28,7 +29,10 @@ class RoachesScene(Scene): def __init__(self): super().__init__() + self._outside_roach_pos = 0 + self._inventory_pos = 0 self._roaches = self.actors.add_layer("roaches", level=10) + self._serums = self.actors.add_layer("serums", 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) @@ -40,6 +44,7 @@ class RoachesScene(Scene): self._init_bg() self._init_seats() self._init_roaches(world.roaches) + self._update_serums(world.serums) def _init_bg(self): self.actors.default.add(self._vehicle.background) @@ -59,6 +64,15 @@ class RoachesScene(Scene): if i < len(self._seats): roach_actor.pos = self._seats[i].pos + def _update_serums(self, serums): + self._serums.clear() + if not serums: + return + self._inventory_pos %= len(serums) + serum_actor = self._serums.add( + big_serums.assemble(serums[self._inventory_pos])) + serum_actor.pos = self._inventory_pad.center + def _init_pads(self): self._roach_pad = self._pads.add( Actor("roach_management/roach_pad", anchor=("left", "bottom"))) @@ -95,20 +109,23 @@ class RoachesScene(Scene): (TOOLBAR_LEFT_X, TOOLBAR_TOP_Y), self._eject_roach) def _roach_left(self): - print("Cycle outside roaches left.") + self._outside_roach_pos -= 1 def _roach_right(self): - print("Cycle outside roaches right.") + self._outside_roach_pos += 1 def _inventory_left(self): - print("Cycle inventory left.") + self._inventory_pos -= 1 def _inventory_right(self): - print("Cycle inventory right.") + self._inventory_pos += 1 def _eject_roach(self): print("Eject roach.") + def update(self, world, dt): + self._update_serums(world.serums) + def on_key_down(self, key, mod, unicode): if key == keys.ESCAPE: from .menu import MenuScene -- 2.34.1