From: Simon Cross Date: Sun, 4 Sep 2016 22:07:17 +0000 (+0200) Subject: Separate rendering of lights and light fixtures. X-Git-Tag: tabakrolletjie-v1.0.0~241 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=5e8b94cbf022d8bd105bf6df97eaaea7c9905133;p=tabakrolletjie.git Separate rendering of lights and light fixtures. --- 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: