title: Trouble with working out the angle of from player to cursor in pygame
body: <p>So I'm trying to make the game asteroids but are having trouble with working out the angle of which the spacecraft should look in. I know the basics of trigonometry but with the y-axis flipped I'm getting a bit confused. I've made a mockup of the problem so you don't have to look through the whole code.</p>
  <pre><code>import pygame
  import sys
  import math
  
  DIMENSIONS = (600, 600)
  window = pygame.display.set_mode(DIMENSIONS, pygame.RESIZABLE)
  window.fill((20, 20, 20))
  pygame.display.set_caption(&quot;Pygame template&quot;)
  clock = pygame.time.Clock()
  
  player_pos = pygame.Vector2(275,275)
  player = pygame.Rect(player_pos.xy, (50,50))
  
  looking_vector = pygame.Vector2(1,1)
  
  while True:
  
      window.fill((20,20,20))
  
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              pygame.quit()
              sys.exit()
  
      player = pygame.Rect(player_pos.xy, (50,50))
  
      # Relative position of mouse
      mouse_pos = pygame.mouse.get_pos()
      delta = mouse_pos - player_pos
      
      # Calculate the angle 
      angle_to_mouse = math.atan2(delta.y, delta.x)
      looking_vector.xy = (100*math.cos(angle_to_mouse), 100*math.sin(angle_to_mouse))
      
      # Player rect
      pygame.draw.rect(window, (50, 50, 255), player)
      # Line to mouse
      pygame.draw.line(window, (255,50,50), player_pos + (25,25), pygame.mouse.get_pos())
      # Line in direction to looking_vector
      pygame.draw.line(window, (50,255,50), player_pos + (25,25), player_pos + looking_vector)
  
      pygame.display.update()
      clock.tick(60)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/74Zwv.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/74Zwv.gif" alt="Demonstration of the problem" /></a></p>
  <p>As you can see in the image above the red line - which is only a line between the center of the rectangle and the mouse position - is completely fine but when it comes to the green line it is a bit off.</p>
  <p>This is pretty much the effect I get in my asteroid game only that it's pretty much fine if the player stays close to the axes. However if the player moves further away from either one of them the effect amplifies and the looking vector is completely in the wrong direction.</p>