X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=tabakrolletjie%2Flights.py;h=84318d15e253616dbe529fcd5a0f0d869e8a1ad2;hb=1a207c0ab976690b60d2a61fa95ff7990f214de1;hp=39b1815fc782b02972ef9d91233d44d7b9b739d8;hpb=1f2682e60071bce98ded8f52747a3742e056d272;p=tabakrolletjie.git diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index 39b1815..84318d1 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -76,6 +76,10 @@ class LightManager(object): for light in self._lights: light.render_fitting(surface) + def tick(self): + for light in self._lights: + light.tick() + class BaseLight(object): """ Common light functionality. """ @@ -93,7 +97,7 @@ class BaseLight(object): def __init__( self, colour, position, intensity=1.0, - radius_limits=(None, None), angle_limits=(None, None)): + radius_limits=(None, None), angle_limits=None): self.colour = colour self.position = pymunk.Vec2d(position) self.on = True @@ -119,6 +123,7 @@ class BaseLight(object): if self.body.space is not None: space.remove(self.body, *self.body.shapes) self.ray_manager.generate_rays(space, self.position) + self.ray_manager.set_angle_limits(self.angle_limits) ray_shapes = self.ray_manager.polys() space.add(self.body, self.fitting, *ray_shapes) @@ -155,12 +160,7 @@ class BaseLight(object): white, black = (255, 255, 255), (0, 0, 0) ray_mask.fill(black) - for shape in self.body.shapes: - if shape is self.fitting: - continue - pygame_poly = [ - pymunk.pygame_util.to_pygame(v, surface) for v in - shape.get_vertices()] + for pygame_poly in self.ray_manager.pygame_polys(surface): pygame.draw.polygon(ray_mask, white, pygame_poly, 0) pygame.draw.aalines(ray_mask, white, True, pygame_poly, 1) @@ -193,9 +193,21 @@ class BaseLight(object): pymunk.pygame_util.to_pygame(self.fitting.offset, surface), int(self.fitting.radius)) + def tick(self): + pass + class SpotLight(BaseLight): def __init__(self, **kw): kw.pop("direction", None) kw.pop("spread", None) + self.angular_velocity = kw.pop("angular_velocity", None) super(SpotLight, self).__init__(**kw) + + def tick(self): + if self.angular_velocity: + start, end = self.angle_limits + start = (start + self.angular_velocity) % 360.0 + end = (end + self.angular_velocity) % 360.0 + self.angle_limits = (start, end) + self.ray_manager.set_angle_limits(self.angle_limits)