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):
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):