From: adrianna Date: Fri, 9 Sep 2016 20:13:29 +0000 (+0200) Subject: started adding fittings to lights X-Git-Tag: tabakrolletjie-v1.0.0~154 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=34bf27ff5767c844cecd4f80d89a8d5d928efdfd;p=tabakrolletjie.git started adding fittings to lights --- diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index 59bbe17..f0ec535 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -11,6 +11,7 @@ import pygame.rect 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 ^ ( @@ -94,6 +95,8 @@ class BaseLight(object): "white": (255, 255, 255), } + FITTING_IMG = None + # cached surfaces _surface_cache = {} @@ -111,6 +114,7 @@ class BaseLight(object): 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): @@ -197,17 +201,24 @@ class BaseLight(object): dt.lap("blitted surface") dt.end() + def get_image(self): + if self._image is None: + self._image = loader.load_image("64", self.FITTING).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 = "spotlight.png" + def __init__(self, **kw): kw.pop("direction", None) kw.pop("spread", None)