made light fixtures smaller
[tabakrolletjie.git] / tabakrolletjie / lights.py
index 59bbe173bccc20ff36d5402cc2b65ca9a7aa10bc..e546b292851510f5b3452d68b1a1d63b7f7c9608 100644 (file)
@@ -11,6 +11,8 @@ import pygame.rect
 from .constants import LIGHT_CATEGORY, FITTINGS_CATEGORY
 from .rays import RayPolyManager
 from .utils import DetailedTimer
+from .loader import loader
+from .transforms import Multiply
 
 LIGHT_FILTER = pymunk.ShapeFilter(
     mask=pymunk.ShapeFilter.ALL_MASKS ^ (
@@ -94,6 +96,8 @@ class BaseLight(object):
         "white": (255, 255, 255),
     }
 
+    FITTING_IMG = None
+
     # cached surfaces
     _surface_cache = {}
 
@@ -111,6 +115,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 +202,34 @@ class BaseLight(object):
         dt.lap("blitted surface")
         dt.end()
 
+    def get_image(self):
+        if self._image is None:
+            fitting_colour = self.COLOURS[self.colour]
+            self._image = loader.load_image(
+                "48", self.FITTING_IMG,
+                transform=Multiply(colour=fitting_colour))
+        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 - 24, ry - 24), None, 0)
 
     def tick(self):
         pass
 
 
+class Lamp(BaseLight):
+    FITTING_IMG = "lamp.png"
+
+    def __init__(self, **kw):
+        kw.pop("direction", None)
+        kw.pop("spread", None)
+        super(Lamp, self).__init__(**kw)
+
+
 class SpotLight(BaseLight):
+    FITTING_IMG = "spotlight.png"
+
     def __init__(self, **kw):
         kw.pop("direction", None)
         kw.pop("spread", None)