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
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)
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: