Cycle through serums.
authorSimon Cross <hodgestar@gmail.com>
Fri, 4 Mar 2016 22:43:07 +0000 (00:43 +0200)
committerSimon Cross <hodgestar@gmail.com>
Fri, 4 Mar 2016 22:43:07 +0000 (00:43 +0200)
koperkapel/scenes/roach_management.py

index 935b3cbacd94d3b8c1924cd5d9d4cf799306ba21..f960a5e18eccbf8d6a4d9f340ab614248459fb3a 100644 (file)
@@ -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