Place roach seats.
authorSimon Cross <hodgestar@gmail.com>
Fri, 4 Mar 2016 19:21:05 +0000 (21:21 +0200)
committerSimon Cross <hodgestar@gmail.com>
Fri, 4 Mar 2016 19:21:05 +0000 (21:21 +0200)
koperkapel/scenes/roaches.py
koperkapel/vehicles/base.py
koperkapel/vehicles/walking.py

index 342f23cd2a57a592cfe4c3600a33a631b83addb7..cecd6ef30d2ff6e29233729b7db727009001ecdc 100644 (file)
@@ -11,6 +11,8 @@ 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)
 
 
@@ -28,6 +30,7 @@ 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._seats = self.actors.add_layer("seats", level=5)
         self._buttons = self.actors.add_layer("buttons", level=6)
         self._init_pads()
         self._init_buttons()
@@ -38,12 +41,15 @@ class RoachesScene(Scene):
         self._init_seats()
 
     def _init_bg(self):
-        self.actors.default.add(Actor("vehicles/walking/background"))
         self.actors.default.add(self._vehicle.background)
 
     def _init_seats(self):
-        print("Seats:")
-        print([seat.pos for seat in self._vehicle.seats])
+        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(
index 27373a5f1eb881c658b2f00021d4e21e5482e65e..09090048d5991b449f7a8f2a7c6a0599ae0dbac1 100644 (file)
@@ -1,13 +1,15 @@
 """ Base class for vehicles.  """
 
+from pgzero.actor import Actor
+
 
 class Vehicle:
     """ Vehicle base class.
 
     A vehicle should have the following attributes:
 
-    * seats -- list of roach seats.
     * background -- actor representing background for management scene
+    * seats -- list of roach seats.
     """
 
     vehicle_types = {}
@@ -30,6 +32,7 @@ class Vehicle:
 class Seat:
     """ A space in a vehicle for a roach.
 
+    * background -- actor representing the seat.
     * pos -- (x, y) position of the seat relative to the centre of the vehicle.
       x and y may be numbers from approximately -1.0 to 1.0. They will be
       multiplied by the approximate_radius of the vehicle.
@@ -37,7 +40,8 @@ class Seat:
       seat
     """
 
-    def __init__(self, pos, allowed=None):
+    def __init__(self, actor, pos, allowed=None):
+        self.actor = actor
         self.pos = pos
         self.allowed = allowed or (lambda roach: True)
 
index f8198923d921d61f1809b18746fd5833540233aa..adcdfc931f87b276e7d3be3e79ad54069076ad52 100644 (file)
@@ -1,17 +1,19 @@
 """ A vehicle to represent roaches on foot. """
 
 import math
+from pgzero.actor import Actor
 from .base import Vehicle, Seat
-from ..actors.buttons import TextButton
 
 
 class Walking(Vehicle):
 
     def __init__(self):
+        self.background = Actor("vehicles/walking/background")
         n_seats = 6
         d_theta = 2 * math.pi / n_seats
         self.seats = [
-            Seat(pos=(math.sin(i * d_theta), math.cos(i * d_theta)))
+            Seat(
+                actor=Actor("vehicles/walking/seat"),
+                pos=(math.sin(i * d_theta), math.cos(i * d_theta)))
             for i in range(n_seats)
         ]
-        self.background = TextButton("Walking Background")