title: Image lags and stutters when moving
body: <p>For some reason when I run the program, my baddie image (asteroid) lags and stutters when it moves however the target does not. I have tried putting <code>pygame.display.update()</code> under each movement code however it just flickers. Also, I switched the position of the movement code for the target and baddie which resulted in the target lagging and stuttering.</p>
  
  <pre><code>import pygame, sys, random
  pygame.init()
  
  def game():
      width = 800
      height = 600
      screen = pygame.display.set_mode((width,height))
      pygame.display.set_caption("Asteroid Dodger")
      background = pygame.image.load("field_of_stars_full.jpg")
  
  
      player = pygame.image.load("Silver_Surfer.png")
      px = 350
      py = 450
      baddie = pygame.image.load("Asteroid.png")
      baddiepos = baddie.get_rect()
      target = pygame.image.load("Cosmic_Clump.png")
      targetpos = [0,0]
  
      gamespeed = 100
      speed = [gamespeed*random.randint(1,3),gamespeed*random.randint(1,3)]
      speed2 = [gamespeed*10,gamespeed*10]
      clock = pygame.time.Clock()
      movex = movey = 0
  
      targetvisible = True
      playervisible = True
  
      font = pygame.font.Font(None,36)
  
      score = 0
      scoretext = font.render("Score: " + str(score), 2, (255,255,255))
      lives = 3
      livestext = font.render("Lives: " + str(lives),2, (255,255,255))
  
  
      while True:
  
  
          screen.blit(background, (0,0))
          screen.blit(player, (px,py))
  
          scoretext = font.render("Score: " + str(score), 2, (255,255,255))
          livestext = font.render("Lives: " + str(lives), 2, (255,255,255))
          screen.blit(scoretext, (20,20))
          screen.blit(livestext, (670,20))
  
          if targetvisible == True:
              seconds = clock.tick()/1000.0
              targetpos[0] += seconds*speed[0]
              targetpos[1] += seconds*speed[1]
              screen.blit(target, targetpos)
          else:
              screen.blit(target, targetpos)
  
  
  
          if playervisible == True:
              seconds = clock.tick()/1000.0
              baddiepos[0] += seconds*speed2[0]
              baddiepos[1] += seconds*speed2[1]
              screen.blit(baddie, baddiepos)
          else:
              screen.blit(baddie, baddiepos)
  
          pygame.display.update()
  
  
          for event in pygame.event.get():
              if event.type == pygame.QUIT or event.type == pygame.K_ESCAPE:
                  pygame.quit()
  
              elif event.type == pygame.KEYDOWN:
                  if event.key == pygame.K_RIGHT:
                          movex = 2
                  elif event.key == pygame.K_LEFT:
                          movex = -2
                          player = pygame.transform.flip(player, 1, 0)
                  elif event.key == pygame.K_DOWN:
                          movey = 2
                  elif event.key == pygame.K_UP:
                          movey = -2
  
              elif event.type == pygame.KEYUP:
                  if event.key == pygame.K_RIGHT:
                          movex = 0
                  elif event.key == pygame.K_LEFT:
                          movex = 0
                          player = pygame.transform.flip(player, 1, 0)
                  elif event.key == pygame.K_DOWN:
                          movey = 0
                  elif event.key == pygame.K_UP:
                          movey = 0
                  elif event.key == pygame.K_ESCAPE:
                          pygame.quit()
  
          px += movex
          py += movey
  
          if targetpos[0]+60 &gt; width or targetpos[0]+15 &lt; 0: 
              speed[0] = -speed[0]            
              targetpos[0] += seconds*speed[0]
  
          if targetpos[1]+70 &gt; height or targetpos[1]+30 &lt; 0:
              speed[1] = -speed[1]
              targetpos[1] += seconds*speed[1]
  
          if abs(targetpos[0]-px)&lt;20 and abs(targetpos[1]-py)&lt;20:
              targetvisible = False
              score += 10
              targetpos[0] = random.randint(0,720)
              targetpos[1] = random.randint(0,520)
              screen.blit(target, (targetpos))          
              targetvisible = True
  
  
          if baddiepos[0] &gt; width or baddiepos[0] &lt; 0:
              speed2[0] = -speed2[0]
              baddiepos[0] += seconds*speed2[0]
  
          if baddiepos[1] &gt; height or baddiepos[1] &lt; 0:
              speed2[1] = -speed2[1]
              baddiepos[1] += seconds*speed2[1]
  
          if abs(baddiepos[0]-px)&lt;20 and (baddiepos[1]-py)&lt;20:
              playervisble = False
              lives -= 1
              baddiepos[0] = random.randint(0,720)
              baddiepos[1] = random.randint(0,520)
              screen.blit(baddie, (baddiepos))
              playervisible = True
  
          if px &gt; 800:
              px = 0
          elif px &lt; 0:
              px = 800
  
          if py &gt; 600:
              py = 0
          elif py &lt; 0:
              py = 600
  </code></pre>