Rename roach management scene module.
authorSimon Cross <hodgestar@gmail.com>
Fri, 4 Mar 2016 19:35:33 +0000 (21:35 +0200)
committerSimon Cross <hodgestar@gmail.com>
Fri, 4 Mar 2016 19:35:33 +0000 (21:35 +0200)
koperkapel/scenes/menu.py
koperkapel/scenes/roach_management.py [new file with mode: 0644]
koperkapel/scenes/roaches.py [deleted file]

index ce09cb5ccb2afa8b9505affb6b7b02172ba12db5..a902d3ab3aa9be265a7c5f016ddf919132f0cc09 100644 (file)
@@ -18,7 +18,8 @@ class MenuScene(Scene):
             TextButton("Play", action=self.change_to_level),
             TextButton("View Last Generated Level",
                        action=self.change_to_viewer),
-            TextButton("Manage Roaches", action=self.change_to_roaches),
+            TextButton("Manage Roaches",
+                       action=self.change_to_roach_management),
             TextButton("Credits", action=self.change_to_credits),
             TextButton("Quit", action=self.quit),
         ]
@@ -41,8 +42,8 @@ class MenuScene(Scene):
             ChangeSceneEvent(ViewLevelScene())
         ]
 
-    def change_to_roaches(self):
-        from .roaches import RoachesScene
+    def change_to_roach_management(self):
+        from .roach_management import RoachesScene
         return [ChangeSceneEvent(RoachesScene())]
 
     def change_to_credits(self):
diff --git a/koperkapel/scenes/roach_management.py b/koperkapel/scenes/roach_management.py
new file mode 100644 (file)
index 0000000..cecd6ef
--- /dev/null
@@ -0,0 +1,129 @@
+""" Roach management scene. """
+
+from pgzero.constants import keys, mouse
+from pgzero.actor import Actor
+from ..actors.buttons import TextButton, ImageButton
+from ..constants import WIDTH, HEIGHT
+from ..vehicles.base import Vehicle
+from .base import Scene, ChangeSceneEvent
+
+
+TOOLBAR_LEFT_X = WIDTH * 3 // 4
+TOOLBAR_TOP_Y = 0
+TOOLBAR_MID_Y = HEIGHT * 1 // 2
+VEHICLE_MID_X = WIDTH * 3 // 8
+VEHICLE_MID_Y = HEIGHT * 1 // 2
+BUTTON_INSET = (20, 20)
+
+
+def inset_button(pos, d):
+    return (
+        pos[0] + d[0] * BUTTON_INSET[0],
+        pos[1] + d[1] * BUTTON_INSET[1])
+
+
+class RoachesScene(Scene):
+    """ Roach management scene. """
+
+    def __init__(self):
+        super().__init__()
+        self._roach_actors = {}
+        self._roaches = self.actors.add_layer("roaches", 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)
+        self._init_pads()
+        self._init_buttons()
+
+    def enter(self, world):
+        self._vehicle = Vehicle.by_type(world.vehicles.current)
+        self._init_bg()
+        self._init_seats()
+
+    def _init_bg(self):
+        self.actors.default.add(self._vehicle.background)
+
+    def _init_seats(self):
+        vrad = self._vehicle.approximate_radius
+        for seat in self._vehicle.seats:
+            seat_actor = self._seats.add(seat.actor)
+            seat_actor.pos = (
+                seat.pos[0] * vrad + VEHICLE_MID_X,
+                seat.pos[1] * vrad + VEHICLE_MID_Y)
+
+    def _init_pads(self):
+        self._roach_pad = self._pads.add(
+            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", anchor=("left", "top")))
+        self._inventory_pad.pos = (TOOLBAR_LEFT_X, TOOLBAR_MID_Y)
+
+    def _add_button(self, name, anchor, inset, pos, action):
+        button = self._buttons.add(
+            ImageButton(name, anchor=anchor, action=action))
+        button.pos = inset_button(pos, inset)
+        return button
+
+    def _init_buttons(self):
+        self._add_button(
+            "roach_management/left_button", ("left", "bottom"), (1, -1),
+            self._roach_pad.bottomleft, self._roach_left)
+
+        self._add_button(
+            "roach_management/right_button", ("right", "bottom"), (-1, -1),
+            self._roach_pad.bottomright, self._roach_right)
+
+        self._add_button(
+            "roach_management/left_button", ("left", "bottom"), (1, -1),
+            self._inventory_pad.bottomleft, self._inventory_left)
+
+        self._add_button(
+            "roach_management/right_button", ("right", "bottom"), (-1, -1),
+            self._inventory_pad.bottomright, self._inventory_right)
+
+        self._add_button(
+            "roach_management/eject_button", ("right", "top"), (-1, 1),
+            (TOOLBAR_LEFT_X, TOOLBAR_TOP_Y), self._eject_roach)
+
+    def _roach_left(self):
+        print("Cycle outside roaches left.")
+
+    def _roach_right(self):
+        print("Cycle outside roaches right.")
+
+    def _inventory_left(self):
+        print("Cycle inventory left.")
+
+    def _inventory_right(self):
+        print("Cycle inventory right.")
+
+    def _eject_roach(self):
+        print("Eject roach.")
+
+    def update(self, world, dt):
+        for i, roach in enumerate(world.roaches):
+            if roach.name in self._roach_actors:
+                actor = self._roach_actors[roach.name]
+            else:
+                actor = TextButton("%s [%s]" % (
+                    roach.name,
+                    ", ".join("%s=%s" % kv for kv in sorted(
+                        roach.attributes.items()),
+                    )))
+                self._roach_actors[roach.name] = actor
+                self._roaches.add(actor)
+            # TODO: remove missing roaches
+            actor.pos = (300, 100 + i * 100)
+
+    def on_key_down(self, key, mod, unicode):
+        if key == keys.ESCAPE:
+            from .menu import MenuScene
+            return [ChangeSceneEvent(MenuScene())]
+
+    def on_mouse_down(self, pos, button):
+        if button == mouse.LEFT:
+            for actor in self.actors.buttons:
+                if actor.collidepoint(pos):
+                    actor.action()
+                    break
diff --git a/koperkapel/scenes/roaches.py b/koperkapel/scenes/roaches.py
deleted file mode 100644 (file)
index cecd6ef..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-""" Roach management scene. """
-
-from pgzero.constants import keys, mouse
-from pgzero.actor import Actor
-from ..actors.buttons import TextButton, ImageButton
-from ..constants import WIDTH, HEIGHT
-from ..vehicles.base import Vehicle
-from .base import Scene, ChangeSceneEvent
-
-
-TOOLBAR_LEFT_X = WIDTH * 3 // 4
-TOOLBAR_TOP_Y = 0
-TOOLBAR_MID_Y = HEIGHT * 1 // 2
-VEHICLE_MID_X = WIDTH * 3 // 8
-VEHICLE_MID_Y = HEIGHT * 1 // 2
-BUTTON_INSET = (20, 20)
-
-
-def inset_button(pos, d):
-    return (
-        pos[0] + d[0] * BUTTON_INSET[0],
-        pos[1] + d[1] * BUTTON_INSET[1])
-
-
-class RoachesScene(Scene):
-    """ Roach management scene. """
-
-    def __init__(self):
-        super().__init__()
-        self._roach_actors = {}
-        self._roaches = self.actors.add_layer("roaches", 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)
-        self._init_pads()
-        self._init_buttons()
-
-    def enter(self, world):
-        self._vehicle = Vehicle.by_type(world.vehicles.current)
-        self._init_bg()
-        self._init_seats()
-
-    def _init_bg(self):
-        self.actors.default.add(self._vehicle.background)
-
-    def _init_seats(self):
-        vrad = self._vehicle.approximate_radius
-        for seat in self._vehicle.seats:
-            seat_actor = self._seats.add(seat.actor)
-            seat_actor.pos = (
-                seat.pos[0] * vrad + VEHICLE_MID_X,
-                seat.pos[1] * vrad + VEHICLE_MID_Y)
-
-    def _init_pads(self):
-        self._roach_pad = self._pads.add(
-            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", anchor=("left", "top")))
-        self._inventory_pad.pos = (TOOLBAR_LEFT_X, TOOLBAR_MID_Y)
-
-    def _add_button(self, name, anchor, inset, pos, action):
-        button = self._buttons.add(
-            ImageButton(name, anchor=anchor, action=action))
-        button.pos = inset_button(pos, inset)
-        return button
-
-    def _init_buttons(self):
-        self._add_button(
-            "roach_management/left_button", ("left", "bottom"), (1, -1),
-            self._roach_pad.bottomleft, self._roach_left)
-
-        self._add_button(
-            "roach_management/right_button", ("right", "bottom"), (-1, -1),
-            self._roach_pad.bottomright, self._roach_right)
-
-        self._add_button(
-            "roach_management/left_button", ("left", "bottom"), (1, -1),
-            self._inventory_pad.bottomleft, self._inventory_left)
-
-        self._add_button(
-            "roach_management/right_button", ("right", "bottom"), (-1, -1),
-            self._inventory_pad.bottomright, self._inventory_right)
-
-        self._add_button(
-            "roach_management/eject_button", ("right", "top"), (-1, 1),
-            (TOOLBAR_LEFT_X, TOOLBAR_TOP_Y), self._eject_roach)
-
-    def _roach_left(self):
-        print("Cycle outside roaches left.")
-
-    def _roach_right(self):
-        print("Cycle outside roaches right.")
-
-    def _inventory_left(self):
-        print("Cycle inventory left.")
-
-    def _inventory_right(self):
-        print("Cycle inventory right.")
-
-    def _eject_roach(self):
-        print("Eject roach.")
-
-    def update(self, world, dt):
-        for i, roach in enumerate(world.roaches):
-            if roach.name in self._roach_actors:
-                actor = self._roach_actors[roach.name]
-            else:
-                actor = TextButton("%s [%s]" % (
-                    roach.name,
-                    ", ".join("%s=%s" % kv for kv in sorted(
-                        roach.attributes.items()),
-                    )))
-                self._roach_actors[roach.name] = actor
-                self._roaches.add(actor)
-            # TODO: remove missing roaches
-            actor.pos = (300, 100 + i * 100)
-
-    def on_key_down(self, key, mod, unicode):
-        if key == keys.ESCAPE:
-            from .menu import MenuScene
-            return [ChangeSceneEvent(MenuScene())]
-
-    def on_mouse_down(self, pos, button):
-        if button == mouse.LEFT:
-            for actor in self.actors.buttons:
-                if actor.collidepoint(pos):
-                    actor.action()
-                    break