def draw(self, screen, camera):
if not self.waypoints:
return
waypoint_color = tuple(self.colors["waypoint"])
goal_color = tuple(self.colors["goal"])
black = tuple(self.colors["black"])
# for i in range(len(self.waypoints) - 1):
# pygame.draw.line(screen, waypoint_color, camera.world_to_screen(*self.waypoints[i]), camera.world_to_screen(*self.waypoints[i+1]), 2)
for i, wp in enumerate(self.waypoints):
color = goal_color if i == self.current_index else waypoint_color
pygame.draw.circle(screen, color, camera.world_to_screen(*wp[:2]), 8)
pygame.draw.circle(screen, black, camera.world_to_screen(*wp[:2]), 8, 2)
# =========================
# Círculo transparente
# =========================
if self.show_tolerance_circle:
radius_px = max(5, int(self.goal_tolerance * camera.scale))
circle_surface = pygame.Surface(
(radius_px * 2, radius_px * 2),
pygame.SRCALPHA
)
color2 = (*color, 120)
pygame.draw.circle(
circle_surface,
color2,
(radius_px, radius_px),
radius_px
)
screen_pos = camera.world_to_screen(*wp[:2])
screen.blit(
circle_surface,
(screen_pos[0] - radius_px,
screen_pos[1] - radius_px)
)
theta = wp[2]
if not np.isnan(theta):
px, py = camera.world_to_screen(wp[0], wp[1])
arrow_len = max(20, int(0.5 * camera.scale))
tip_x = px + arrow_len * np.cos(theta)
tip_y = py - arrow_len * np.sin(theta)
pygame.draw.line(
screen,
black,
(px, py),
(tip_x, tip_y),
3
)
head_size = 8
pygame.draw.line(
screen,
black,
(tip_x, tip_y),
(
tip_x - head_size*np.cos(theta - np.pi/6),
tip_y + head_size*np.sin(theta - np.pi/6)
),
3
)
pygame.draw.line(
screen,
black,
(tip_x, tip_y),
(
tip_x - head_size*np.cos(theta + np.pi/6),
tip_y + head_size*np.sin(theta + np.pi/6)
),
3
)