X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=tabakrolletjie%2Fobstacles.py;h=b368626431994464b7f7650ea60971ac471ecce0;hb=403f74bb5689f3231a1e23b500a09aee35259b57;hp=d187a599294de659c54a70a3e08a27ba5692230f;hpb=2e20539ebb1efedfdc675962961c10b6985c09a7;p=tabakrolletjie.git diff --git a/tabakrolletjie/obstacles.py b/tabakrolletjie/obstacles.py index d187a59..b368626 100644 --- a/tabakrolletjie/obstacles.py +++ b/tabakrolletjie/obstacles.py @@ -4,6 +4,25 @@ import pymunk import pymunk.pygame_util import pygame.draw +from .constants import OBSTACLE_CATEGORY + +OBSTACLE_FILTER = pymunk.ShapeFilter(categories=OBSTACLE_CATEGORY) + + +class ObstacleManager(object): + """ Manages a set of obstacles. """ + + def __init__(self, space, gamestate): + self._space = space + self._obstacles = [ + BaseObstacle.load(cfg) for cfg in gamestate.station["obstacles"]] + for obs in self._obstacles: + obs.add(self._space) + + def render(self, surface): + for obs in self._obstacles: + obs.render(surface) + class BaseObstacle(object): def __init__(self): @@ -13,6 +32,8 @@ class BaseObstacle(object): def add(self, space): if self.body.space is not None: space.remove(self.body, *self.body.shapes) + for shape in self.shapes: + shape.filter = OBSTACLE_FILTER space.add(self.body, *self.shapes) def render(self, surface):