From: Neil Date: Wed, 7 Sep 2016 13:30:30 +0000 (+0200) Subject: Add shape-based light query X-Git-Tag: tabakrolletjie-v1.0.0~205 X-Git-Url: https://git.ctpug.org.za/?p=tabakrolletjie.git;a=commitdiff_plain;h=9f403d319ac457967248b17a8f3c0de945bdc613 Add shape-based light query --- 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)