Separate rendering of lights and light fixtures.
authorSimon Cross <hodgestar@gmail.com>
Sun, 4 Sep 2016 22:07:17 +0000 (00:07 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sun, 4 Sep 2016 22:07:17 +0000 (00:07 +0200)
tabakrolletjie/lights.py
tabakrolletjie/scenes/night.py

index ecb6cedd44391a5e2e293b01b4d3bd37f67f1087..52031419611eff93d23f0c68e6daf221520d05c0 100644 (file)
@@ -65,6 +65,14 @@ def calculate_ray_polys(space, body, position):
 class BaseLight(object):
     """ Common light functionality. """
 
+    COLOURS = {
+        "red": (255, 0, 0),
+        "green": (0, 255, 0),
+        "blue": (0, 255, 255),
+        "yellow": (255, 255, 0),
+        "white": (255, 255, 255),
+    }
+
     def __init__(self, colour, position):
         self.body = pymunk.Body(0, 0, pymunk.body.Body.STATIC)
         self.colour = colour
@@ -105,19 +113,22 @@ class SpotLight(BaseLight):
         return ray_polys
 
     def render(self, surface):
-        subsurface = surface.copy()
         pygame.draw.circle(
             surface, (255, 255, 0),
             pymunk.pygame_util.to_pygame(self.position, surface), 5)
+
+    def render_light(self, surface):
+        subsurface = surface.copy()
+        light_colour = self.COLOURS[self.colour]
         for shape in self.body.shapes:
             pygame_poly = [
                 pymunk.pygame_util.to_pygame(v, surface) for v in
                 shape.get_vertices()]
             pygame.draw.polygon(
-                subsurface, (200, 200, 200), pygame_poly, 0)
+                subsurface, light_colour, pygame_poly, 0)
             pygame.draw.aalines(
-                subsurface, (200, 200, 200), True, pygame_poly, 1)
-        subsurface.set_alpha(200)
+                subsurface, light_colour, True, pygame_poly, 1)
+        subsurface.set_alpha(50)
         surface.blit(subsurface, (0, 0), None)
 
 
index bb362b53a42b33281449819eb4255e737d80e214..16d8cf692a6aa9336cf2e008c30a07e019afd4a4 100644 (file)
@@ -24,6 +24,8 @@ class NightScene(BaseScene):
 
     def render(self, surface, gamestate):
         surface.fill((0, 0, 155))
+        for light in self._lights:
+            light.render_light(surface)
         for obs in self._obstacles:
             obs.render(surface)
         for light in self._lights: