Add back light radius checks.
authorSimon Cross <hodgestar@gmail.com>
Fri, 9 Sep 2016 21:48:20 +0000 (23:48 +0200)
committerSimon Cross <hodgestar@gmail.com>
Fri, 9 Sep 2016 21:48:20 +0000 (23:48 +0200)
tabakrolletjie/lights.py
tabakrolletjie/rays.py

index 2952da5c86680eada28d63130e425bf017179e87..34160f006de713ce58163cf54307f0995047cc12 100644 (file)
@@ -65,7 +65,10 @@ class LightManager(object):
         point_info_list = self._space.point_query(
             pos, max_distance, pymunk.ShapeFilter(mask=LIGHT_CATEGORY))
         lights = [p.shape.body.light for p in point_info_list]
-        return [light for light in lights if light.on]
+        return [
+            light for light in lights
+            if light.on and light.ray_manager.reaches(pos)
+        ]
 
     def light_query(self, shape):
         """Query the lights by shape"""
@@ -75,7 +78,10 @@ class LightManager(object):
         shape_info_list = self._space.shape_query(shape)
         shape.filter = old_filter
         lights = [p.shape.body.light for p in shape_info_list]
-        return [light for light in lights if light.on]
+        return [
+            light for light in lights
+            if light.on and light.ray_manager.reaches(shape.body.position)
+        ]
 
     def render_light(self, surface):
         for light in self._lights:
index 9e5a1bf6d0050534ec79fda916e55c7c01d0a595..6ff8a6ea526033de129d82aafe735a35ef71a213 100644 (file)
@@ -125,6 +125,10 @@ class RayPolyManager(object):
     def min_radius_setter(self, value):
         self._min_radius = value or 0.0
 
+    def reaches(self, position):
+        distance = self.position.get_distance(self.position)
+        return (self._min_radius <= distance <= self._max_radius)
+
     def _set_radius_limits(self, radius_limits):
         if radius_limits is None or not radius_limits[0]:
             self._min_radius = 0