title: how to stop movement if the object hits the boundary in pygame
body: <pre><code>import pygame
  import random
  
  pygame.init()
  black = (0,0,0)
  red = (255,0,0)
  
  display_width = 800
  display_height = 600
  FPS = 20
  
  gameDisplay = pygame.display.set_mode((display_width,display_height))
  pygame.display.set_caption("The Space Jumpers")
  
  img = pygame.image.load('starship2.png')
  spritesize = 50
  boundlimit = 200
  
  clock = pygame.time.Clock()
  
  font = pygame.font.SysFont(None, 25)
  
  def gameLoop():
      gameExit = False
      gameOver = False
      lead_x = display_width / 2
      lead_y = display_height / 2
      xchange = 0
      ychange = 0
  
      randBlockX = random.randrange(0,boundlimit+1)
      randBlockY = random.randrange(0,575)
  
      while not gameExit:
          gameDisplay.blit(img, [lead_x,lead_y])
          pygame.display.update()
          for event in pygame.event.get():
              if event.type == pygame.QUIT:
                  gameExit = True
              if event.type == pygame.KEYDOWN:
                  if event.key == pygame.K_LEFT:
                      xchange = -spritesize / 2
                      ychange = 0
                  if event.key == pygame.K_RIGHT:
                      xchange = spritesize / 2
                      ychange = 0
                  if event.key == pygame.K_UP:
                      ychange = -spritesize / 2
                      xchange = 0
                  if event.key == pygame.K_DOWN:
                      ychange = spritesize / 2
                      xchange = 0
              if event.type == pygame.KEYUP:
                  if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                      xchange = 0
                  if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
                      ychange = 0
  
  
  
  
  
  
  
  
  
  
  
          lead_x += xchange
          lead_y += ychange 
  
          gameDisplay.fill(black)
          pygame.draw.rect(gameDisplay,red, [randBlockX, randBlockY, 600, 25])
  
          if (lead_x+spritesize &lt; randBlockX and randBlockY&lt;lead_y&lt;randBlockY+25) :
              randBlockX = random.randrange(0,boundlimit+1)
              randBlockY = random.randrange(0,575)
          elif (lead_x+spritesize &lt; randBlockX and randBlockY&lt;lead_y&lt;randBlockY+25 ):
              randBlockX = random.randrange(0,boundlimit+1)
              randBlockY = random.randrange(0,575)
          elif (lead_x &gt; randBlockX+600 and randBlockY&lt;lead_y&lt;randBlockY+25):
              randBlockX = random.randrange(0,boundlimit+1)
              randBlockY = random.randrange(0,575)
          elif (lead_x &gt; randBlockX+600 and randBlockY&lt;lead_y&lt;randBlockY+25):
              randBlockX = random.randrange(0,boundlimit+1)
              randBlockY = random.randrange(0,575)
  
  
  
  
  
  
          clock.tick(FPS)   
  
  
      pygame.quit()
      quit()
  
  gameLoop()
  </code></pre>
  
  <p>This is my current code and in this code when the object(sprite) hits the boundary, it keeps on moving but what I want to do is, I want to stop the movement of the object when it hits the boundary, for example when the object hits the left boundary it shouldnt move left anymore. You kind of get the idea, its a simple game </p>