Untitled

 avatar
unknown
plain_text
a year ago
1.2 kB
7
Indexable
class Fish (pygame.sprite.Sprite):
  def __init__(self):
    super().__init__()
    self.frame_list = init_animation_frames("Fish_Swim.png", 4)
    self.current_frame_index = 0
    self.last_time_frame_updated = pygame.time.get_ticks() 
    self.image=self.frame_list[self.current_frame_index]
    self.rect = self.image.get_rect() 
    self.rect.center = (0, random.randint(100,600))   # set the initial position of the knight
    self.velocity = 0   # used to determine fall speed
    self.current_frame_index = 0
    self.last_time_frame_updated = 0
    self.mask = pygame.mask.from_surface(self.image)
    self.frame_count = 0
  def update(self):
        self.frame_count += 1
        if self.frame_count % FRAME_INTERVAL == 0:
            self.rect.x += FISH_SPEED



def spawn_fish():
  global last_spawn_time
  if random.random() < SPAWN_CHANCE:  # spawn chance is a percent chance to spawn
      current_spawn_time = pygame.time.get_ticks()    # get current time in ms
      if current_spawn_time - last_spawn_time > SPAWN_INTERVAL:   # check if enough time has elapsed
        # create new skeleton
        fish = Fish()
        fish_group.add(fish)
        all_sprites.add(fish)
        last_spawn_time = current_spawn_time
Leave a Comment