1 """ Obstacles for light and space mould. """
4 import pymunk.pygame_util
8 class BaseObstacle(object):
10 self.body = pymunk.Body(0, 0, pymunk.body.Body.STATIC)
14 if self.body.space is not None:
15 space.remove(self.body, *self.body.shapes)
16 space.add(self.body, *self.shapes)
18 def render(self, surface):
19 raise NotImplementedError("Obstacles should implement .render().")
22 def load(cls, config):
24 obstacle_type = kw.pop("type")
26 c for c in cls.__subclasses__()
27 if c.__name__.lower() == obstacle_type]
28 return obstacle_class(**kw)
31 class Wall(BaseObstacle):
33 def __init__(self, vertices):
34 super(Wall, self).__init__()
35 self.shapes.append(pymunk.Poly(self.body, vertices))
37 def render(self, surface):
38 for shape in self.shapes:
40 pymunk.pygame_util.to_pygame(v, surface) for v in
42 pygame.draw.polygon(surface, (0, 0, 0), pygame_poly)