def die(self): self.lives -= 1 if self.lives > 0: play_sound(constants.DIE_SOUND_FILE) else: play_sound(constants.GAMEOVER_SOUND_FILE)
def process_enemies(self, enemies): hit_list = pygame.sprite.spritecollide(self, enemies, False) if len(hit_list) > 0 and self.invincibility == 0: play_sound(constants.HURT_SOUND_FILE) self.hearts -= 1 self.invincibility = int(0.75 * constants.FPS)
def jump(self, blocks): self.rect.y += 1 hit_list = pygame.sprite.spritecollide(self, blocks, False) if len(hit_list) > 0: self.vy = -1 * self.jump_power play_sound(constants.JUMP_SOUND_FILE) self.rect.y -= 1
def process_coins(self, coins): hit_list = pygame.sprite.spritecollide(self, coins, True) for coin in hit_list: play_sound(constants.COIN_SOUND_FILE) self.score += coin.value
def check_flag(self, level): hit_list = pygame.sprite.spritecollide(self, level.flag, False) if len(hit_list) > 0: level.completed = True play_sound(constants.LEVELUP_SOUND_FILE)
def process_powerups(self, powerups): hit_list = pygame.sprite.spritecollide(self, powerups, True) for p in hit_list: play_sound(constants.POWERUP_SOUND_FILE) p.apply(self)