""" Be prepared. """
+import math
+
import pygame.display
import pygame.locals as pgl
self._paused = False
self._tool = None
self._light_color = None
+ self._dragging = None
for turnip_data in gamestate.turnips:
turnip = Turnip(space=self._space, **turnip_data)
# Turnips grow at dawn
# TODO: Add error sound or something
pass
+ def _update_light_angle(self, pos):
+ # 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
+
def _place_spotlight(self, gamestate, colour, ev):
if self._seeds > 5:
pos = pymunk.pygame_util.from_pygame(ev.pos,
"type": "spotlight",
"colour": colour,
"position": pos,
- "angle_limits": [0, 90],
+ "direction": 45,
+ "spread": 90,
"intensity": 0.5,
"radius_limits": [0, 100],
}
pos = pymunk.pygame_util.from_pygame(ev.pos,
pygame.display.get_surface())
# Bail if we're too close to an existing light
- if self._lights.nearest(pos, max_distance=25):
+ if self._lights.nearest(ev.pos, surfpos=True, max_distance=25):
return
self._seeds -= 3
self._update_toolbar(gamestate)
# Not tool, so check lights
self._lights.toggle_nearest(ev.pos, surfpos=True)
print self._lights.lit_by(ev.pos, surfpos=True)
- elif ev.button == 3 and self._tool:
- self._tool = None
- self._unset_cursor()
+ elif ev.button == 3:
+ light = self._lights.nearest(ev.pos, surfpos=True,
+ max_distance=5.0)
+ if light:
+ # Start drag to rotate light
+ self._dragging = light
+ elif self._tool:
+ # Unset tool
+ self._tool = None
+ self._unset_cursor()
+ elif ev.type == pgl.MOUSEMOTION:
+ if self._dragging:
+ # Calculate angle between current position and mouse pos
+ self._update_light_angle(ev.pos)
+ elif ev.type == pgl.MOUSEBUTTONUP:
+ self._dragging = None
@debug_timer("day.tick")
def tick(self, gamestate):