+ surface.blit(self._soil, (0, 0))
+
+ for turnip in self._turnips:
+ turnip.render(surface)
+ self._lights.render_light(surface)
+ self._obstacles.render(surface)
+ self._lights.render_fittings(surface)
+ surface.blit(self._toolbar, (120, 10), None)
+ for tool in self._tools:
+ tool.render(surface)
+ for light_tool in self._light_toolbar:
+ light_tool.render(surface)
+ self._draw_cursor(surface)
+ if self._game_over_text:
+ for surf, pos in self._game_over_text:
+ surface.blit(surf, pos)
+
+ def _draw_light_toolbar(self, light_config, x):
+ height = SCREEN_SIZE[1] - 80
+ self._light_toolbar = []
+ colour_combos = light_config["available_colours"]
+ for combo in colour_combos:
+ colours = combo.split("/")
+ light_fitting = light_fitting_by_type(light_config["type"])
+ light_tool = ImageButton(
+ "32", light_fitting, transform=ColourWedges(colours=colours),
+ pos=(x, height), name=combo)
+ light_tool.colours = colours
+ 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_light(self, gamestate, cfg, colours, ev):
+ cfg = cfg.copy()
+ cost = cfg.pop("cost")
+ cfg.pop("available_colours")
+ if self._seeds > cost:
+ 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 -= cost
+ self._update_toolbar(gamestate)
+ cfg["position"] = pos
+ cfg["colours"] = colours
+ gamestate.station["lights"].append(cfg)
+ self._lights.add_light(cfg)