Update angle in gamestate as well for passing to night
authorNeil <neil@dip.sun.ac.za>
Sat, 10 Sep 2016 10:54:36 +0000 (12:54 +0200)
committerNeil <neil@dip.sun.ac.za>
Sat, 10 Sep 2016 10:55:13 +0000 (12:55 +0200)
tabakrolletjie/rays.py
tabakrolletjie/scenes/day.py

index b4142a3e6694f8ecaeb4f67264a4bb270ca7a025..621ded65a0e25f557a1d9f6db4f92ad9f62f7ac8 100644 (file)
@@ -88,6 +88,8 @@ class RayPolyManager(object):
         self._start = None  # normal vector in direction of start angle limit
         self._end = None  # normal vector in direction of end angle limit
         self._set_angle_limits(direction, spread)
+        if direction:
+            self.direction = direction  # Update direction
         self._max_radius = None  # maximum radius in pixels
         self._min_radius = None  # minimum radius in pixels
         self._set_radius_limits(radius_limits)
index 933f16bad399df9dd430b3737e0b5f2ee21bd5e9..162a30b9a1317bf110729665bfcbabbe4ce9015c 100644 (file)
@@ -116,14 +116,19 @@ class DayScene(BaseScene):
                 # TODO: Add error sound or something
                 pass
 
-    def _update_light_angle(self, pos):
+    def _update_light_angle(self, pos, gamestate):
         # Update the angle of the given light
         pos = pymunk.pygame_util.to_pygame(pos, pygame.display.get_surface())
         distance = pos - self._dragging.position
         angle = math.atan2(distance[1], distance[0])
         # Set light angle to this position
         self._dragging.ray_manager.direction = math.degrees(angle)
-        # TODO: Update gamestate with new angle
+        # Hackily update gamestate with new angle
+        for light_cfg in gamestate.station["lights"]:
+            light_pos = pymunk.Vec2d(light_cfg["position"])
+            if light_pos.get_dist_sqrd(self._dragging.position) < 5.0:
+                light_cfg["direction"] = math.degrees(angle)
+                break
 
     def _place_spotlight(self, gamestate, colour, ev):
         if self._seeds > 5:
@@ -218,7 +223,7 @@ class DayScene(BaseScene):
                     print self._lights.lit_by(ev.pos, surfpos=True)
             elif ev.button == 3:
                 light = self._lights.nearest(ev.pos, surfpos=True,
-                                             max_distance=5.0)
+                                             max_distance=20.0)
                 if light:
                     # Start drag to rotate light
                     self._dragging = light
@@ -229,7 +234,7 @@ class DayScene(BaseScene):
         elif ev.type == pgl.MOUSEMOTION:
             if self._dragging:
                 # Calculate angle between current position and mouse pos
-                self._update_light_angle(ev.pos)
+                self._update_light_angle(ev.pos, gamestate)
         elif ev.type == pgl.MOUSEBUTTONUP:
             self._dragging = None