--- /dev/null
+""" 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()
--- /dev/null
+""" 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")