X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=tabakrolletjie%2Fscenes%2Fday.py;h=468c4ca995b416ef320a5c662c5661a161444213;hb=9b0872898e6cf9d4e5860de577b8ac9565593b6d;hp=589f8b25d03d5fad28cf20889fe36b5fea05ae03;hpb=1511ad34b86a11fe1433fa7dfd1de865ab8f7c1d;p=tabakrolletjie.git diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index 589f8b2..468c4ca 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -1,5 +1,7 @@ """ Be prepared. """ +import math + import pygame.display import pygame.locals as pgl @@ -34,6 +36,7 @@ class DayScene(BaseScene): 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 @@ -109,10 +112,24 @@ class DayScene(BaseScene): self._turnips.append(turnip) self._seeds -= 1 self._update_toolbar(gamestate) - except TurnipInvalidPosition as e: + except TurnipInvalidPosition: # TODO: Add error sound or something pass + 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) + # 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: pos = pymunk.pygame_util.from_pygame(ev.pos, @@ -124,9 +141,10 @@ class DayScene(BaseScene): self._update_toolbar(gamestate) cfg = { "type": "spotlight", - "colour": colour, + "colours": [colour], "position": pos, - "angle_limits": [0, 90], + "direction": 45, + "spread": 90, "intensity": 0.5, "radius_limits": [0, 100], } @@ -138,13 +156,13 @@ class DayScene(BaseScene): 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) cfg = { "type": "lamp", - "colour": colour, + "colours": [colour], "position": pos, "intensity": 0.5, } @@ -203,9 +221,22 @@ class DayScene(BaseScene): # 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=20.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, gamestate) + elif ev.type == pgl.MOUSEBUTTONUP: + self._dragging = None @debug_timer("day.tick") def tick(self, gamestate):