title: How to make a block move back and forth in pygame
body: <p>I am trying to make a moving platform so when the platforms reaches a curtain point it is supposed to reverse direction and go back but from what I can see it looks like it is vibrating back and fort 
  program link: <a href="https://drive.google.com/file/d/0BzvvQCByWwmAQThfdkEtSlRKa1k/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/0BzvvQCByWwmAQThfdkEtSlRKa1k/view?usp=sharing</a></p>
  
  <p>here is my code:</p>
  
  <pre><code>class lbuild(pygame.sprite.Sprite):
  #This class represents alevel builder. It derives from the "Sprite" class in Pygame.
  
  def __init__(self, color, width, height,x,y):
      # Call the parent class (Sprite) constructor
      super().__init__()
  
      self.image = pygame.Surface([width, height])
      self.image.fill(WHITE)
      self.image.set_colorkey(WHITE)
  
      # Draw the car (a rectangle!)
      pygame.draw.rect(self.image, color, [0, 0, width, height])
  
       # Fetch the rectangle object that has the dimensions of the image.
      self.rect = self.image.get_rect()
      self.rect.x=x
      self.rect.y=y
  all_sprites_list = pygame.sprite.Group()
  movblock=pygame.sprite.Group()#sprite group
  def level1():
       global all_sprites_list
       global movblock
       xpos=0
  
       for x in range(50):
  
          all_sprites_list.add(lbuild(GREY,20,20,xpos,680))
          xpos =xpos+20
      ypos=660
      xpos2 =40
  
      for x in range(2):
          all_sprites_list.add(lbuild(black,60,20,xpos2,ypos))
          ypos=ypos-20
      mblk=lbuild(RED,100,20,120,600)#draws the block
      movblock.add(mblk)#adds it to the sprite group
  
  
  
  
  
     clock=pygame.time.Clock()
  
     while True:
              for event in pygame.event.get():
                  if event.type==QUIT:
                      pygame.quit()
                      sys.exit()
              #Game Logic
              all_sprites_list.update()
  
  
              #Drawing on Screen
              screen.fill(WHITE)
             #Draw The Road
             spd=5
  
             if mblk.rect.x&gt;200:#supposed to cheak if the block x postion a has reached 200 and the reverse its direction but instead it looks like it is vibrating
                 spd= -spd
             if mblk.rect.x&lt;100:
                 spd= -spd
             mblk.rect.x+=spd
  
             #Now let's draw all the sprites in one go. (For now we only have 1 sprite!)
             all_sprites_list.draw(screen)
             movblock.draw(screen)
  
          #Refresh Screen
              pygame.display.flip()
  
         #Number of frames per secong e.g. 60
         clock.tick(60)
  </code></pre>