title: How to fix strange rendering issue in 2d pygame using math
body: <p>Im trying to create a 2D game engine that will later be upgraded to 3D in a Duke Nukem 3D style. Right now I'm making a top down 2D view where I can check all the coordinates are in the right place then I can start work on the 3D engine. It is meant to work by allowing the player to move in 2D and showing where the player is and what direction they are facing, and also drawing a single "wall". When I move I want the player to stay static and the map to move, but rendering the wall doesnt work correctly and I get incorrect lines that move away slowly. This is the video I got the concept from: <a href="https://www.youtube.com/watch?v=HQYsFshbkYw" rel="nofollow noreferrer">https://www.youtube.com/watch?v=HQYsFshbkYw</a>
  It will explain how everything is meant to work.</p>
  
  <pre><code>import pygame, math
  pygame.init()
  CLOCK = pygame.time.Clock()
  DISPLAYWIDTH, DISPLAYHEIGHT = 200, 200
  YELLOW, RED, GREEN, BLUE, BLACK, WHITE, GREY = (255, 255, 0), (255, 0, 0), (0, 255, 0), (0, 0, 255), (0, 0, 0), (255, 255, 255), (128, 128, 128)
  
  #players starting coords, angle they are facing, how much they are rotating between frames and how much they move forward between frames
  px, py, pf, pr, pm = 50, 50, -90, 0, 0
  
  #position of wall
  x1, y1, x2, y2 =10, 10, 150, 60
  
  
  DISPLAYSURF = pygame.display.set_mode((DISPLAYWIDTH, DISPLAYHEIGHT))
  
  
  
  #This returns the coords of the point (x, y) after rotating around (a, b) by theta degrees
  def rotAroundPoint(x, y, a, b, theta):
      theta = theta * (math.pi/180) #convert to radians
      return (math.cos(theta) * (x - a) - math.sin(theta) * (y-b) + x, math.sin(theta) * (x - a) + math.cos(theta) * (y-b) + y)
  
  
  
  while True:
      DISPLAYSURF.fill(BLACK)
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              pygame.quit()
  
      #check for keys (w for forward, a and d for rotating)
      keys = pygame.key.get_pressed()
      if keys[pygame.K_w]:
          pm = 2
      else:
          pm = 0
      if keys[pygame.K_a]:
          pr = -3
      elif keys[pygame.K_d]:
          pr = 3
      else:
          pr = 0
  
      #rotate the player
      pf += pr
  
      #move the player forward along the direction they are facing
      px += pm * math.cos(math.radians(pf))
      py += pm * math.sin(math.radians(pf))
  
      #the coords of where to draw the wall
      rotPoint1 = rotAroundPoint(x1, y1, px, py, pf)
      rotPoint2 = rotAroundPoint(x2, y2, px, py, pf)
  
      #draw everything and update
      pygame.draw.line(DISPLAYSURF, YELLOW, rotPoint1, rotPoint2)
      pygame.draw.aaline(DISPLAYSURF, GREY, (50, 50), (50 + math.cos(math.radians(pf)) * 10, 50 + math.sin(math.radians(pf)) * 10))
      pygame.draw.circle(DISPLAYSURF, WHITE, (50, 50), 2)
      pygame.display.flip()
      CLOCK.tick(35)
  </code></pre>
  
  <p>it should just keep the player at (50, 50) facing up and move the map but that doesnt happen</p>