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
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):
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
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()]
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):