title: How do I continuously trigger an action at certain time intervals? Enemy shoots constant beam instead of bullets in pygame
body: <p>Trying to make an enemy in pygame that shoots bullets in a straight line in pygame. I've managed to make the enemy shoot, but it shoots a constant beam of bullets instead of spacing them out. Is there any way to space out the bullets?</p>
  
  <p>This is the class for the enemy</p>
  
  <pre><code>class Boss(pygame.sprite.Sprite):
      def __init__(self):
          pygame.sprite.Sprite.__init__(self)
          self.image = pygame.Surface((100, 70))
          self.image.fill(white)
          self.rect = self.image.get_rect()
          self.rect.centerx = WIDTH / 2
          self.rect.y = (WIDTH / 2) - 500
          self.speedy = 3
  
      def update(self):
          self.rect.y += self.speedy
          if self.rect.y &gt;= 30:
              self.rect.y = 30
  
      def shoot(self):
          bossbullet = Bossbullet(self.rect.centerx, self.rect.bottom)
          all_sprites.add(bossbullet)
          bossbullets.add(bossbullet)
  
  
  class Bossbullet(pygame.sprite.Sprite):
      def __init__(self, x, y):
          pygame.sprite.Sprite.__init__(self)
          self.image = pygame.Surface((10, 20))
          self.image.fill(white)
          self.rect = self.image.get_rect()
          self.rect.bottom = y
          self.rect.centerx = x
          self.speedy = -10
  
      def update(self):
          self.rect.y -= self.speedy
  
          if self.rect.bottom &lt; 0:
              self.kill()
  
  all_sprites = pygame.sprite.Group()
  boss = Boss()
  all_sprites.add(boss)
  bossbullets = pygame.sprite.Group()
  
  </code></pre>
  
  <p>this is the loop in which the game runs and the enemy shoots</p>
  
  <pre><code>running = True
  while running:
  
      clock.tick(FPS)
      if boss.rect.y &gt;= 30:
          boss.shoot()
  </code></pre>