Add obstacle manager and move nearest calculation to light manager.
[tabakrolletjie.git] / tabakrolletjie / obstacles.py
index 32df5b4561d6672c3931d5a436eb7e914c3f6dfc..b368626431994464b7f7650ea60971ac471ecce0 100644 (file)
@@ -9,6 +9,21 @@ 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):
         self.body = pymunk.Body(0, 0, pymunk.body.Body.STATIC)