I want to move my enemy across the imaginary hypotenuse of a triangle in pygame from a start_x, start_y variable to a target_x, target_y, how would I do that? This is part of my utility file
def polar_to_rectangularD(degrees, hypotenuse=1.0, inverted_y=True):
opp = math.sin(math.degrees(degrees))*hypotenuse
adj = math.cos(math.degrees(degrees))*hypotenuse
if inverted_y:
opp = -opp
return opp,adj
def angle_towardsD(start_x, start_y, target_x, target_y, inverted_y=True):
opp = target_y - start_y
adj = target_x - start_x
if inverted_y:
opp = -opp
angle = math.atan2(opp, adj)
return math.degrees(angle)
And this is a portion of what I attempted to do with it in my main
if wall_spawn == 1:
enemy_y = player_ymax + player_half_height + enemy_radius
enemy_direction = -1
spawn_angle = utility.angle_towardsD((win_width/6),650,(win_width/2),-100)
enemy_x_offset, enemy_y_offset = utility.polar_to_rectangularD(spawn_angle,1)
enemy_y -= enemy_y_offset
enemy_movement += enemy_x_offset
#enemy_movement is set to None
