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
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 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(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])
def _init_pads(self):
self._roach_pad = self._pads.add(
--- /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")
self._build_roach("roeginald", strength=3),
self._build_roach("roichard", quickness=3),
]
+ state["vehicles"] = {
+ "current": "walking",
+ "available": ["walking"],
+ }
state["level"] = {
"name": "level1",
}