From 5e8b94cbf022d8bd105bf6df97eaaea7c9905133 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Mon, 5 Sep 2016 00:07:17 +0200 Subject: [PATCH] Separate rendering of lights and light fixtures. --- tabakrolletjie/lights.py | 19 +++++++++++++++---- tabakrolletjie/scenes/night.py | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index ecb6ced..5203141 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -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) diff --git a/tabakrolletjie/scenes/night.py b/tabakrolletjie/scenes/night.py index bb362b5..16d8cf6 100644 --- a/tabakrolletjie/scenes/night.py +++ b/tabakrolletjie/scenes/night.py @@ -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: -- 2.34.1