title: Moving a sprite to the other side when a sprite moves off screen Pygame
body: <p>If I have a sprite (See below) that I can move around, the screen with the arrow keys. (Up and Down moves forwards and backwards, left and right turn.)
  I was wondering if it would be possible to move to the other side of the screen when it goes off? But so it works whatever the angle is, and so that if it's driven half into the edge, half appears on one side. (Kind of like snake) Is there a way of doing this?</p>
  
  <p><a href="https://i.stack.imgur.com/Y7u2V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y7u2V.png" alt="Car"></a></p>
  
  <p>Here's my code so far:</p>
  
  <pre><code>import sys, pygame, math
  from pygame.locals import *
  pygame.init()
  
  SCREEN = pygame.display.set_mode((800, 600))
  car = pygame.transform.scale(pygame.image.load('Car.png').convert_alpha(), (64, 64))
  pygame.display.set_caption('Car Game')
  pygame.display.set_icon(car)
  FPS = pygame.time.Clock()
  
  carX  = 400
  carY  = 100
  angle = 90
  speed = 0
  
  while True:
  
      if angle == 360: angle = 0
      if  angle == -1: angle = 359
  
      SCREEN.fill((0,0,0))
  
      for event in pygame.event.get():
          if event.type == QUIT:
              pygame.quit()
              sys.exit()
  
      keys = pygame.key.get_pressed()
      if keys[K_a] or keys[K_LEFT]:
          angle += speed
      elif keys[K_d] or keys[K_RIGHT]:
          angle -= speed
      if keys[K_w] or keys[K_UP]:
          speed += 1
      elif keys[K_s] or keys[K_DOWN]:
          speed -= 0.5
  
      carX += speed*math.cos(math.radians(angle))
      carY -= speed*math.sin(math.radians(angle))
      speed *= 0.95
  
      rotcar = pygame.transform.rotate(car, angle)
      position = rotcar.get_rect(center = (carX,carY))
      SCREEN.blit(rotcar, position)
  
      pygame.display.update()
      FPS.tick(24)
  </code></pre>