rotating spotlight fixture
[tabakrolletjie.git] / tabakrolletjie / lights.py
index fef2b44d2133e32c2f43d2e1366ad00101e8559e..7b2c26380c9800ded9540fcb281766d87903b679 100644 (file)
@@ -9,6 +9,7 @@ import pygame.display
 import pygame.draw
 import pygame.locals as pgl
 import pygame.rect
+import pygame.transform
 
 from .constants import LIGHT_CATEGORY, FITTINGS_CATEGORY, COLOURS
 from .rays import RayPolyManager
@@ -258,7 +259,6 @@ class BaseLight(object):
         else:
             self.colour = self.colour_cycle[self.colour_pos]
             self.on = True
-        self.invalidate_fitting_image()
 
     def tick(self):
         pass
@@ -312,6 +312,17 @@ class SpotLight(BaseLight):
         self.angular_velocity = kw.pop("angular_velocity", None)
         super(SpotLight, self).__init__(**kw)
 
+    def fitting_image(self):
+        fitting_image = super(SpotLight, self).fitting_image()
+        rot_fitting_image = pygame.transform.rotozoom(fitting_image, self.ray_manager.direction - 90, 1)
+
+        rot_rect = fitting_image.get_rect().copy()
+        rot_rect.center = rot_fitting_image.get_rect().center
+        rot_fitting_image = rot_fitting_image.subsurface(rot_rect).copy()
+        
+        return rot_fitting_image
+        
+
     def tick(self):
         if self.angular_velocity:
             self.ray_manager.direction -= self.angular_velocity