Add roach management buttons.
authorSimon Cross <hodgestar@gmail.com>
Wed, 2 Mar 2016 21:29:37 +0000 (23:29 +0200)
committerSimon Cross <hodgestar@gmail.com>
Wed, 2 Mar 2016 21:29:37 +0000 (23:29 +0200)
koperkapel/scenes/roaches.py

index 09169f3ac80bd4566933c8dd97b50303fc110144..b5c2715e126e2db4268a27418d716cf1b1f323ca 100644 (file)
@@ -7,6 +7,18 @@ from ..constants import WIDTH, HEIGHT
 from .base import Scene, ChangeSceneEvent
 
 
+TOOLBAR_LEFT_X = WIDTH * 3 // 4
+TOOLBAR_TOP_Y = 0
+TOOLBAR_MID_Y = HEIGHT * 1 // 2
+BUTTON_INSET = (20, 20)
+
+
+def inset_button(pos, dx, dy):
+    return (
+        pos[0] + dx * BUTTON_INSET[0],
+        pos[1] + dy * BUTTON_INSET[1])
+
+
 class RoachesScene(Scene):
     """ Roach management scene. """
 
@@ -15,15 +27,47 @@ class RoachesScene(Scene):
         self._roach_actors = {}
         self._roaches = self.actors.add_layer("roaches", level=10)
         self._pads = self.actors.add_layer("pads", level=5)
+        self._buttons = self.actors.add_layer("buttons", level=6)
+        self._init_bg()
         self._init_pads()
+        self._init_buttons()
+
+    def _init_bg(self):
+        self.actors.default.add(Actor("vehicles/walking/background"))
 
     def _init_pads(self):
         self._roach_pad = self._pads.add(
-            Actor("roach_management/roach_pad"))
-        self._roach_pad.pos = (WIDTH * (7/8), HEIGHT * (1/4))
+            Actor("roach_management/roach_pad", anchor=("left", "bottom")))
+        self._roach_pad.pos = (TOOLBAR_LEFT_X, TOOLBAR_MID_Y)
         self._inventory_pad = self._pads.add(
-            Actor("roach_management/inventory_pad"))
-        self._inventory_pad.pos = (WIDTH * (7/8), HEIGHT * (3/4))
+            Actor("roach_management/inventory_pad", anchor=("left", "top")))
+        self._inventory_pad.pos = (TOOLBAR_LEFT_X, TOOLBAR_MID_Y)
+
+    def _init_buttons(self):
+        self._roach_left = self._buttons.add(
+            Actor("roach_management/left_button", anchor=("left", "bottom")))
+        self._roach_left.pos = inset_button(
+            self._roach_pad.bottomleft, 1, -1)
+
+        self._roach_right = self._buttons.add(
+            Actor("roach_management/right_button", anchor=("right", "bottom")))
+        self._roach_right.pos = inset_button(
+            self._roach_pad.bottomright, -1, -1)
+
+        self._inventory_left = self._buttons.add(
+            Actor("roach_management/left_button", anchor=("left", "bottom")))
+        self._inventory_left.pos = inset_button(
+            self._inventory_pad.bottomleft, 1, -1)
+
+        self._inventory_right = self._buttons.add(
+            Actor("roach_management/right_button", anchor=("right", "bottom")))
+        self._inventory_right.pos = inset_button(
+            self._inventory_pad.bottomright, -1, -1)
+
+        self._road_eject = self._buttons.add(
+            Actor("roach_management/eject_button", anchor=("right", "top")))
+        self._road_eject.pos = inset_button(
+            (TOOLBAR_LEFT_X, TOOLBAR_TOP_Y), -1, 1)
 
     def update(self, world, dt):
         for i, roach in enumerate(world.roaches):