Add filter to obstacle shapes.
authorSimon Cross <hodgestar@gmail.com>
Sun, 4 Sep 2016 20:39:29 +0000 (22:39 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sun, 4 Sep 2016 20:39:29 +0000 (22:39 +0200)
tabakrolletjie/obstacles.py

index d187a599294de659c54a70a3e08a27ba5692230f..32df5b4561d6672c3931d5a436eb7e914c3f6dfc 100644 (file)
@@ -4,6 +4,10 @@ import pymunk
 import pymunk.pygame_util
 import pygame.draw
 
+from .constants import OBSTACLE_CATEGORY
+
+OBSTACLE_FILTER = pymunk.ShapeFilter(categories=OBSTACLE_CATEGORY)
+
 
 class BaseObstacle(object):
     def __init__(self):
@@ -13,6 +17,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):