09090048d5991b449f7a8f2a7c6a0599ae0dbac1
[koperkapel.git] / koperkapel / vehicles / base.py
1 """ Base class for vehicles.  """
2
3 from pgzero.actor import Actor
4
5
6 class Vehicle:
7     """ Vehicle base class.
8
9     A vehicle should have the following attributes:
10
11     * background -- actor representing background for management scene
12     * seats -- list of roach seats.
13     """
14
15     vehicle_types = {}
16     approximate_radius = 200
17
18     @classmethod
19     def by_type(cls, vehicle_type):
20         return cls.vehicle_types.get(vehicle_type)()
21
22     @classmethod
23     def register(cls, vehicle_cls):
24         cls.vehicle_types[vehicle_cls.__name__.lower()] = vehicle_cls
25
26     @classmethod
27     def register_all(cls):
28         from .walking import Walking
29         cls.register(Walking)
30
31
32 class Seat:
33     """ A space in a vehicle for a roach.
34
35     * background -- actor representing the seat.
36     * pos -- (x, y) position of the seat relative to the centre of the vehicle.
37       x and y may be numbers from approximately -1.0 to 1.0. They will be
38       multiplied by the approximate_radius of the vehicle.
39     * allowed -- f(roach) for checking whether a roach may occupy the
40       seat
41     """
42
43     def __init__(self, actor, pos, allowed=None):
44         self.actor = actor
45         self.pos = pos
46         self.allowed = allowed or (lambda roach: True)
47
48
49 Vehicle.register_all()