from .constants import LIGHT_CATEGORY, FITTINGS_CATEGORY
from .rays import RayPolyManager
from .utils import DetailedTimer
+from .loader import loader
LIGHT_FILTER = pymunk.ShapeFilter(
mask=pymunk.ShapeFilter.ALL_MASKS ^ (
"white": (255, 255, 255),
}
+ FITTING_IMG = None
+
# cached surfaces
_surface_cache = {}
self.fitting.filter = FITTINGS_FILTER
self.body.light = self
self.ray_manager = RayPolyManager(self.body, LIGHT_FILTER)
+ self._image = None
@classmethod
def load(cls, config):
ray_mask.fill(black)
for pygame_poly in self.ray_manager.pygame_polys(surface):
pygame.draw.polygon(ray_mask, white, pygame_poly, 0)
- pygame.draw.aalines(ray_mask, white, True, pygame_poly, 1)
+ pygame.draw.polygon(ray_mask, white, pygame_poly, 1)
dt.lap("ray mask rendered")
+ light_colour = self.COLOURS[self.colour]
+ intensity = int(255 * self.intensity)
+ light_colour = light_colour + (intensity,)
+
radius_mask.fill(black)
centre = pymunk.pygame_util.to_pygame(self.position, surface)
pygame.draw.circle(
- radius_mask, white, centre, int(max_radius), 0)
+ radius_mask, light_colour, centre, int(max_radius), 0)
pygame.draw.circle(
radius_mask, black, centre, int(min_radius), 0)
dt.lap("radius mask rendered")
ray_mask.blit(radius_mask, dest_rect, dest_rect, pgl.BLEND_RGBA_MULT)
dt.lap("blitted radius mask to ray mask")
- light_colour = self.COLOURS[self.colour]
- intensity = int(255 * self.intensity)
- light_colour = light_colour + (intensity,)
-
- ray_mask.fill(light_colour, dest_rect, pgl.BLEND_RGBA_MULT)
- dt.lap("coloured ray mask")
-
surface.blit(ray_mask, dest_rect, dest_rect)
dt.lap("blitted surface")
dt.end()
+ def get_image(self):
+ if self._image is None:
+ self._image = loader.load_image("64", self.FITTING_IMG).copy()
+ fitting_colour = self.COLOURS[self.colour]
+ self._image.fill(fitting_colour, None, pgl.BLEND_RGBA_MULT)
+ return self._image
+
def render_fitting(self, surface):
- pygame.draw.circle(
- surface, (255, 255, 0),
- pymunk.pygame_util.to_pygame(self.fitting.offset, surface),
- int(self.fitting.radius))
+ rx, ry = pymunk.pygame_util.to_pygame(self.position, surface)
+ surface.blit(self.get_image(), (rx - 32, ry - 32), None, 0)
def tick(self):
pass
class SpotLight(BaseLight):
+ FITTING_IMG = "spotlight.png"
+
def __init__(self, **kw):
kw.pop("direction", None)
kw.pop("spread", None)