title: How to delete rects/sprites with python and pygame
body: <p>I am working on a game and I wanted to add an ammo box that randomly spawns.  so far the box spawns as expected and if you move over it, it is removed and gives you 200+ ammo.  However, it is only supposed to give 50 ammo.  Then later in the game when the player goes back to that spot they continue to get more ammo.  If I just sit there I end up getting 1000+ ammo.</p>
  
  <p>Here is my ammo class:</p>
  
  <pre><code>class Ammo(pygame.sprite.Sprite):
      def __init__(self, color, x, y, player = None):
          pygame.sprite.Sprite.__init__(self)
  
          self.image = pygame.Surface([20, 20])
          self.image.fill(BLACK)
          self.rect = self.image.get_rect()
          self.rect.x = x
          self.rect.y = y
  
      def update(self):
          pass
  </code></pre>
  
  <p>and here is the game loop:</p>
  
  <pre><code>class Game():
      def __init__(self):
          pygame.init()
  
          screen_width = 850
          screen_height = 640
  
          place_ammo = False
  
          self.screen = pygame.display.set_mode( (screen_width,screen_height) )
  
          pygame.mouse.set_visible(False)
  
          #-----
  
          self.all_sprites_list = pygame.sprite.Group()
          self.block_list = pygame.sprite.Group()
          self.bullet_list = pygame.sprite.Group()
  
          self.blitwave = 1
  
          # --- create sprites ---
  
          self.background = Background()
  
          self.player = Player(self.screen.get_rect(), 0, 370)
          self.all_sprites_list.add(self.player)
          self.ammo = Ammo(self.screen.get_rect(),random.randrange(10,screen_width),random.randint(10,screen_height - 10))
          self.all_sprites_list.add(self.ammo)
  
          self.ammo_amount = 10
          self.on_screen = 1
          self.score = 0
  
          self.crosshair = Crosshair()
  
      def bullet_create(self, start_pos, mouse_pos):
          bullet = Bullet(start_pos, mouse_pos)
  
          self.all_sprites_list.add(bullet)
          self.bullet_list.add(bullet)
  
      def bullets_update(self):
          for bullet in self.bullet_list:
  
              block_hit_list = pygame.sprite.spritecollide(bullet, self.block_list, True)
              screen_width = 850
              screen_height = 640
  
              for block in block_hit_list:
                  self.bullet_list.remove(bullet)
                  self.all_sprites_list.remove(bullet)
                  self.score += 1
                  self.on_screen -= 1
                  self.ammo_chance = self.ammo_amount * 5
                  if self.ammo_chance &gt; 0:
                      self.drop = random.randint(1, self.ammo_chance)
                      print(self.drop)
                  if self.drop &gt; 0 and self.drop &lt; 2:
  
                      print('ammo drop')
                      self.ammo = Ammo(self.screen.get_rect(),random.randrange(10,screen_width),random.randint(10,screen_height - 10))
                      self.all_sprites_list.add(self.ammo)
  
                  if bullet.rect.y &lt; -10:
                      self.bullet_list.remove(bullet)
                      self.all_sprites_list.remove(bullet)
  
      # -------- Main Program Loop -----------
  
      def run(self):
          screen_width = 850
          screen_height = 640
  
          #wave
          self.wave = 1
          self.wave_no = 2
          self.wave_running = True
          block = Block(BLUE, random.randrange(100, screen_width), random.randrange(10, screen_height-10), self.player)
  
          self.block_list.add(block)
          self.all_sprites_list.add(block)
  
          clock = pygame.time.Clock()
  
          self.cash = 1
          self.health = 100
          self.ammo_amount = 10
  
          RUNNING = True
          PAUSED  = False
  
          while RUNNING:
              # --- events ---
              if self.player.health &lt;= 0:
                  RUNNING = False
              for event in pygame.event.get():
  
                  if event.type == pygame.QUIT:
                      RUNNING = PAUSED
  
                  elif event.type == pygame.KEYDOWN:
                      if event.key == pygame.K_SPACE:
                          PAUSED = True
  
                  elif event.type == pygame.KEYUP:
                      if event.key == pygame.K_SPACE:
                          PAUSED = not PAUSED
  
                  elif event.type == pygame.MOUSEBUTTONDOWN and self.ammo_amount &gt; 0:
                      self.bullet_create(self.player, event.pos)
                      self.ammo_amount -= 1
  
                  self.cash = self.score * 5
  
                  if self.on_screen == 0:
                      for i in range(self.wave_no):
                          block = Block(BLUE, random.randrange(100, screen_width), random.randrange(10, screen_height-10), self.player)
  
                          self.block_list.add(block)
                          self.all_sprites_list.add(block)
                          self.on_screen += 1
  
                      self.wave_div = int(self.wave_no / 2)
                      self.wave_no += self.wave_div
                      self.wave += 1
  
                  #wave font 
                  font = pygame.font.SysFont("", 34)
                  self.text_pause = font.render("WAVE " + str(self.wave) * self.blitwave, -1, RED)
                  self.text_pause_rect = self.text_pause.get_rect(center=self.screen.get_rect().center) # center text
  
  
                  #health font
                  self.text_health = font.render("|" * self.player.health, -1, RED)
  
                  #score font
                  self.text_score = font.render("SCORE " + str(self.score), -1, BLACK)
  
                  #cash font
                  self.text_cash = font.render("CASH " + str(self.cash), -1, GREEN)
  
                  #ammo font
                  self.text_ammo = font.render("AMMO " + str(self.ammo_amount), -1, RED)
  
                  # send event to player
                  self.player.event_handler(event)
  
              if not PAUSED:
                  self.all_sprites_list.update()
                  self.bullets_update()
  
              player_rect = pygame.Rect(self.player.rect.x, self.player.rect.y, 20, 20)
              block_rect = pygame.Rect(block.rect.x, block.rect.y, 20, 20)
  
              if player_rect.colliderect(block_rect):
                  self.player.health = self.player.health - 3
  
              if player_rect.colliderect(self.ammo.rect):
                  self.ammo_amount += 50
                  self.all_sprites_list.remove(self.ammo)
  
              self.crosshair.update()
  
              # --- draws ---
              self.background.draw(self.screen)
              self.all_sprites_list.draw(self.screen)
  
              #must be last
              self.screen.blit(self.text_pause, (10, 610))
              self.screen.blit(self.text_score, (700, 585))
              self.screen.blit(self.text_cash, (700, 560))
              self.screen.blit(self.text_ammo, (700, 610))
              self.screen.blit(self.text_health, (10, 10))
              self.crosshair.draw(self.screen)
  
              pygame.display.update() # use flip() OR update()
  
              # --- FPS ---
  
              clock.tick(70)
  
          # --- quit ---
  
          pygame.quit()
  
  #----------------------------------------------------------------------
  
  Game().run()
  </code></pre>