1 """ May it be a light for you in dark places, when all other lights go out.
7 class BaseLight(object):
8 """ Common light functionality. """
10 def __init__(self, colour, position):
11 self.body = pymunk.Body(0, 0, pymunk.body.Body.STATIC)
13 self.position = position
15 def add_to_space(self, space):
16 space.remove(self.body, **self.body.shapes())
17 shapes = self.determine_ray_polys(space)
18 space.add(self.body, **shapes)
20 def determine_ray_polys(self, space):
21 raise NotImplementedError(
22 "Lights should implement .determine_ray_polys.")
25 def load(cls, config):
27 light_type = kw.pop("type")
29 c for c in cls.__subclasses__()
30 if c.__name__.lower() == light_type]
31 return light_class(**kw)
34 class SpotLight(BaseLight):
36 self, colour="white", position=None, direction=90.0, spread=45.0):
37 super(SpotLight, self).__init__(colour, position)
38 self.direction = direction
42 class Lamp(BaseLight):
43 def __init__(self, colour="white", position=None, radius=100.0):
44 super(Lamp, self).__init__(colour, position)