From 9f403d319ac457967248b17a8f3c0de945bdc613 Mon Sep 17 00:00:00 2001 From: Neil Date: Wed, 7 Sep 2016 15:30:30 +0200 Subject: [PATCH] Add shape-based light query --- tabakrolletjie/lights.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index b22bc35..2c691fe 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -20,6 +20,9 @@ FITTINGS_FILTER = pymunk.ShapeFilter( LIGHT_CATEGORY | FITTINGS_CATEGORY), categories=FITTINGS_CATEGORY) +# Just match lights, nothing else +LIT_BY_FILTER = pymunk.ShapeFilter(mask=LIGHT_CATEGORY) + def screen_rays(pos): """ An iterable that returns ordered rays from pos to the edge of the @@ -98,6 +101,16 @@ class LightManager(object): lights = [p.shape.body.light for p in point_info_list] return [light for light in lights if light.on] + def light_query(self, shape): + """Query the lights by shape""" + old_filter = shape.filter + # We need to restrict matches to only the lights + shape.filter = LIT_BY_FILTER + 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] + def render_light(self, surface): for light in self._lights: light.render_light(surface) -- 2.34.1