+ for light_tool in self._light_toolbar:
+ light_tool.render(surface)
+ self._draw_cursor(surface)
+
+ def _draw_light_toolbar(self, light_type, x):
+ self._light_toolbar = []
+ height = SCREEN_SIZE[1] - 80
+ for color in sorted(COLOURS.keys()):
+ light_tool = ImageButton('32', light_type + '.png',
+ pos=(x, height), name=color,
+ transform=Multiply(colour=COLOURS[color]))
+ self._light_toolbar.append(light_tool)
+ x += 40
+
+ def _clear_light_toolbar(self):
+ self._light_toolbar = []
+
+ def _place_seed(self, gamestate, ev):
+ if self._seeds > 0:
+ # plant seed
+ # We don't want top-left to equal the mouse position,
+ # since that looks weird, but we don't want to center
+ # the turnip under the mouse either, since that
+ # causes issues as well, so we compromise
+ pos = (ev.pos[0] - 8, ev.pos[1] - 8)
+ try:
+ turnip = Turnip(age=0, pos=pos, space=self._space)
+ self._turnips.append(turnip)
+ self._seeds -= 1
+ self._update_toolbar(gamestate)
+ 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,
+ pygame.display.get_surface())
+ # Bail if we're too close to an existing light
+ if self._lights.nearest(pos, max_distance=25):
+ return
+ self._seeds -= 5
+ self._update_toolbar(gamestate)
+ cfg = {
+ "type": "spotlight",
+ "colours": [colour],
+ "position": pos,
+ "direction": 45,
+ "spread": 90,
+ "intensity": 0.5,
+ "radius_limits": [0, 100],
+ }
+ gamestate.station["lights"].append(cfg)
+ self._lights.add_light(cfg)
+
+ def _place_lamp(self, gamestate, colour, ev):
+ if self._seeds > 3:
+ 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(ev.pos, surfpos=True, max_distance=25):
+ return
+ self._seeds -= 3
+ self._update_toolbar(gamestate)
+ cfg = {
+ "type": "lamp",
+ "colours": [colour],
+ "position": pos,
+ "intensity": 0.5,
+ }
+ gamestate.station["lights"].append(cfg)
+ self._lights.add_light(cfg)