From def792624a0f6f19cbca3877df2741ed559a4687 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Wed, 2 Mar 2016 23:29:37 +0200 Subject: [PATCH] Add roach management buttons. --- koperkapel/scenes/roaches.py | 52 +++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/koperkapel/scenes/roaches.py b/koperkapel/scenes/roaches.py index 09169f3..b5c2715 100644 --- a/koperkapel/scenes/roaches.py +++ b/koperkapel/scenes/roaches.py @@ -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): -- 2.34.1