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 assign_seats(self, seating):
22 for roach_name, seat in zip(seating, self.seats):
23 seat.roach = roach_name
28 def current(cls, world):
29 vehicle = cls.by_type(world.vehicles.current)
31 world.vehicles[vehicle.vehicle_type].seating)
35 def by_type(cls, vehicle_type):
36 return cls._vehicle_types.get(vehicle_type)()
39 def register(cls, vehicle_cls):
40 cls._vehicle_types[vehicle_cls.__name__.lower()] = vehicle_cls
43 def register_all(cls):
44 from .walking import Walking
49 """ A space in a vehicle for a roach.
51 * pos -- (x, y) position of the seat relative to the centre of the vehicle.
52 x and y may be numbers from approximately -1.0 to 1.0. They will be
53 multiplied by the approximate_radius of the vehicle.
54 * roach -- name of the roach occupying the seat, if any.
55 * allowed -- f(roach) for checking whether a roach may occupy the
59 def __init__(self, vehicle, pos, roach=None, allowed=None):
60 self.vehicle = vehicle
63 self.allowed = allowed or (lambda roach: True)
64 vrad = vehicle.approximate_radius
65 self.vehicle_pos = (pos[0] * vrad, pos[1] * vrad)
68 return Actor("vehicles/%s/seat" % (self.vehicle.vehicle_type,))
71 Vehicle.register_all()