fixed turnip/light positioning bug
[tabakrolletjie.git] / tabakrolletjie / lights.py
index 747ce92e86449ea92102dbbb5b0d73465339dd66..318aefca3ca2579a4c36cc0b373944c2a91b455a 100644 (file)
@@ -59,6 +59,10 @@ class LightManager(object):
         self._lights.append(light)
         light.add(self._space)
 
+    def remove_light(self, light):
+        self._lights.remove(light)
+        light.remove(self._space)
+
     def battery_dead(self):
         self._battery_dead = True
         for light in self._lights:
@@ -155,7 +159,7 @@ class BaseLight(object):
             self.colour_pos = colours.index(start_colour)
             self.colour = start_colour
         self.on = on
-        if not on and len(colours) > 1:
+        if not on:
             self.colour_pos = -1
         self.intensity = intensity
         self.body = pymunk.Body(0, 0, pymunk.body.Body.STATIC)
@@ -207,6 +211,10 @@ class BaseLight(object):
         self.ray_manager.set_space(space)
         self.ray_manager.update_shapes()
 
+    def remove(self, space):
+        if self.body.space is not None:
+            space.remove(self.body, *self.body.shapes)
+
     def _cached_surface(self, name, surface):
         surf = self._surface_cache.get(name)
         if surf is None:
@@ -272,7 +280,7 @@ class BaseLight(object):
 
     def render_fitting(self, surface):
         rx, ry = self.ray_manager.pygame_position(surface)
-        surface.blit(self.fitting_image(), (rx - 24, ry - 24), None, 0)
+        surface.blit(self.fitting_image(), (rx - self.FITTING_RADIUS, ry - self.FITTING_RADIUS), None, 0)
 
     def power_usage(self):
         if not self.on:
@@ -286,6 +294,7 @@ class BaseLight(object):
 
     def off(self):
         self.on = False
+        self.colour_pos = -1
 
     def toggle(self):
         self.colour_pos += 1
@@ -308,7 +317,7 @@ class Lamp(BaseLight):
 
 class PulsatingLamp(BaseLight):
 
-    FITTING_IMG = "lamp.png"
+    FITTING_IMG = "pulsatinglamp.png"
     DEFAULT_PULSE_RANGE = (20, 100)
     DEFAULT_PULSE_VELOCITY = 2
     DEFAULT_INTENSITY_RANGE = (0.0, 0.9)