From: Simon Cross Date: Tue, 6 Sep 2016 19:44:18 +0000 (+0200) Subject: Add circular fitting to lights. X-Git-Tag: tabakrolletjie-v1.0.0~225 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=b44d3280fafd667431d65908cbde8c86bcbe3b19;p=tabakrolletjie.git Add circular fitting to lights. --- diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index 7620c48..c5c72af 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -5,13 +5,20 @@ import pymunk import pymunk.pygame_util import pygame.draw -from .constants import SCREEN_SIZE, LIGHT_CATEGORY +from .constants import ( + SCREEN_SIZE, LIGHT_CATEGORY, FITTINGS_CATEGORY) from .utils import debug_timer LIGHT_FILTER = pymunk.ShapeFilter( - mask=pymunk.ShapeFilter.ALL_MASKS ^ LIGHT_CATEGORY, + mask=pymunk.ShapeFilter.ALL_MASKS ^ ( + LIGHT_CATEGORY | FITTINGS_CATEGORY), categories=LIGHT_CATEGORY) +FITTINGS_FILTER = pymunk.ShapeFilter( + mask=pymunk.ShapeFilter.ALL_MASKS ^ ( + LIGHT_CATEGORY | FITTINGS_CATEGORY), + categories=FITTINGS_CATEGORY) + def screen_rays(pos): """ An iterable that returns ordered rays from pos to the edge of the @@ -70,8 +77,9 @@ class BaseLight(object): def __init__(self, colour, position): self.on = True self.body = pymunk.Body(0, 0, pymunk.body.Body.STATIC) + self.fitting = pymunk.Circle(self.body, 5.0) self.colour = colour - self.position = position + self.position = pymunk.Vec2d(position) @classmethod def load(cls, config): @@ -89,7 +97,8 @@ class BaseLight(object): calculate_ray_polys(space, self.body, self.position)) for shape in shapes: shape.filter = LIGHT_FILTER - space.add(self.body, *shapes) + self.fitting.filter = FITTINGS_FILTER + space.add(self.body, self.fitting, *shapes) def shapes_for_ray_polys(self, ray_polys): return ray_polys @@ -103,6 +112,8 @@ class BaseLight(object): subsurface = surface.copy() light_colour = self.COLOURS[self.colour] for shape in self.body.shapes: + if shape is self.fitting: + continue pygame_poly = [ pymunk.pygame_util.to_pygame(v, surface) for v in shape.get_vertices()] @@ -114,9 +125,11 @@ class BaseLight(object): surface.blit(subsurface, (0, 0), None) def render_fittings(self, surface): + centre = self.position + self.fitting.offset pygame.draw.circle( surface, (255, 255, 0), - pymunk.pygame_util.to_pygame(self.position, surface), 5) + pymunk.pygame_util.to_pygame(centre, surface), + int(self.fitting.radius)) class SpotLight(BaseLight):