X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=koperkapel%2Fvehicles%2Fbase.py;h=f4506d602bfb520c0235ef9b4ac23f6cb475671a;hb=19c2f95f74c4818f494c6a7a654e8aa5c6e4e08c;hp=09090048d5991b449f7a8f2a7c6a0599ae0dbac1;hpb=6cb552f903dce3e3bad9b3f3be829f0996422ae2;p=koperkapel.git diff --git a/koperkapel/vehicles/base.py b/koperkapel/vehicles/base.py index 0909004..f4506d6 100644 --- a/koperkapel/vehicles/base.py +++ b/koperkapel/vehicles/base.py @@ -4,24 +4,41 @@ from pgzero.actor import Actor class Vehicle: - """ Vehicle base class. + """ Vehicle base class. """ - A vehicle should have the following attributes: + vehicle_type = None + approximate_radius = 200 - * background -- actor representing background for management scene - * seats -- list of roach seats. - """ + def __init__(self): + self.seats = self.init_seats() - vehicle_types = {} - approximate_radius = 200 + def roach_management_overlay(self): + return Actor("vehicles/%s/background" % (self.vehicle_type,)) + + def init_seats(self): + raise NotImplementedError("Vehicles should specify a list of seats") + + def seating(self, world): + roach_seating = world.vehicles[self.vehicle_type].seating + roach_seating_numbers = enumerate(zip(roach_seating, self.seats)) + return { + roach: seat_pos + for seat_pos, (roach, _) in roach_seating_numbers if roach + } + + _vehicle_types = {} + + @classmethod + def current(cls, world): + return cls.by_type(world.vehicles.current) @classmethod def by_type(cls, vehicle_type): - return cls.vehicle_types.get(vehicle_type)() + return cls._vehicle_types.get(vehicle_type)() @classmethod def register(cls, vehicle_cls): - cls.vehicle_types[vehicle_cls.__name__.lower()] = vehicle_cls + cls._vehicle_types[vehicle_cls.__name__.lower()] = vehicle_cls @classmethod def register_all(cls): @@ -32,18 +49,24 @@ class Vehicle: class Seat: """ A space in a vehicle for a roach. - * background -- actor representing the seat. * 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. + * roach -- name of the roach occupying the seat, if any. * allowed -- f(roach) for checking whether a roach may occupy the - seat + seat. """ - def __init__(self, actor, pos, allowed=None): - self.actor = actor + def __init__(self, vehicle, pos, roach=None, allowed=None): + self.vehicle = vehicle self.pos = pos + self.roach = roach self.allowed = allowed or (lambda roach: True) + vrad = vehicle.approximate_radius + self.vehicle_pos = (pos[0] * vrad, pos[1] * vrad) + + def actor(self): + return Actor("vehicles/%s/seat" % (self.vehicle.vehicle_type,)) Vehicle.register_all()