Roaches on foot.
authorSimon Cross <hodgestar@gmail.com>
Thu, 3 Mar 2016 22:35:33 +0000 (00:35 +0200)
committerSimon Cross <hodgestar@gmail.com>
Thu, 3 Mar 2016 22:35:33 +0000 (00:35 +0200)
koperkapel/vehicles/base.py [new file with mode: 0644]
koperkapel/vehicles/walking.py [new file with mode: 0644]

diff --git a/koperkapel/vehicles/base.py b/koperkapel/vehicles/base.py
new file mode 100644 (file)
index 0000000..27373a5
--- /dev/null
@@ -0,0 +1,45 @@
+""" Base class for vehicles.  """
+
+
+class Vehicle:
+    """ Vehicle base class.
+
+    A vehicle should have the following attributes:
+
+    * seats -- list of roach seats.
+    * background -- actor representing background for management scene
+    """
+
+    vehicle_types = {}
+    approximate_radius = 200
+
+    @classmethod
+    def by_type(cls, vehicle_type):
+        return cls.vehicle_types.get(vehicle_type)()
+
+    @classmethod
+    def register(cls, vehicle_cls):
+        cls.vehicle_types[vehicle_cls.__name__.lower()] = vehicle_cls
+
+    @classmethod
+    def register_all(cls):
+        from .walking import Walking
+        cls.register(Walking)
+
+
+class Seat:
+    """ A space in a vehicle for a roach.
+
+    * 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.
+    * allowed -- f(roach) for checking whether a roach may occupy the
+      seat
+    """
+
+    def __init__(self, pos, allowed=None):
+        self.pos = pos
+        self.allowed = allowed or (lambda roach: True)
+
+
+Vehicle.register_all()
diff --git a/koperkapel/vehicles/walking.py b/koperkapel/vehicles/walking.py
new file mode 100644 (file)
index 0000000..f819892
--- /dev/null
@@ -0,0 +1,17 @@
+""" A vehicle to represent roaches on foot. """
+
+import math
+from .base import Vehicle, Seat
+from ..actors.buttons import TextButton
+
+
+class Walking(Vehicle):
+
+    def __init__(self):
+        n_seats = 6
+        d_theta = 2 * math.pi / n_seats
+        self.seats = [
+            Seat(pos=(math.sin(i * d_theta), math.cos(i * d_theta)))
+            for i in range(n_seats)
+        ]
+        self.background = TextButton("Walking Background")