1 """ Base class for vehicles. """
3 from pgzero.actor import Actor
7 """ Vehicle base class. """
10 approximate_radius = 200
13 self.seats = self.init_seats()
15 def roach_management_overlay(self):
16 return Actor("vehicles/%s/background" % (self.vehicle_type,))
19 raise NotImplementedError("Vehicles should specify a list of seats")
21 def seating(self, world):
22 roach_seating = world.vehicles[self.vehicle_type].seating
23 roach_seating_numbers = enumerate(zip(roach_seating, self.seats))
26 for seat_pos, (roach, _) in roach_seating_numbers if roach
32 def current(cls, world):
33 return cls.by_type(world.vehicles.current)
36 def by_type(cls, vehicle_type):
37 return cls._vehicle_types.get(vehicle_type)()
40 def register(cls, vehicle_cls):
41 cls._vehicle_types[vehicle_cls.__name__.lower()] = vehicle_cls
44 def register_all(cls):
45 from .walking import Walking
50 """ A space in a vehicle for a roach.
52 * pos -- (x, y) position of the seat relative to the centre of the vehicle.
53 x and y may be numbers from approximately -1.0 to 1.0. They will be
54 multiplied by the approximate_radius of the vehicle.
55 * roach -- name of the roach occupying the seat, if any.
56 * allowed -- f(roach) for checking whether a roach may occupy the
60 def __init__(self, vehicle, pos, roach=None, allowed=None):
61 self.vehicle = vehicle
64 self.allowed = allowed or (lambda roach: True)
65 vrad = vehicle.approximate_radius
66 self.vehicle_pos = (pos[0] * vrad, pos[1] * vrad)
69 return Actor("vehicles/%s/seat" % (self.vehicle.vehicle_type,))
72 Vehicle.register_all()