def push(self) -> None: """Look for block to push and if one is close in direction faced - push it. """ hits = pg.sprite.spritecollide(self, self.game.blocks, False, pg.sprite.collide_circle_ratio(1.2)) hits = [ h for h in hits if is_actor_neighbour_in_direction(self, h, self.facing) ] if hits: hits[0].respond_to_push(self.facing) hits = pg.sprite.spritecollide(self, self.game.walls, False, pg.sprite.collide_circle_ratio(0.75)) if [ h for h in hits if is_actor_neighbour_in_direction(self, h, self.facing) ]: play_sound(self.game.sounds["electric"]) for enemy in self.game.enemies: enemy.stun(wall_check=True)
def initiate_death_sequence(self) -> None: """If Player dies remove life, freeze and start a timer for death animation. """ play_sound(self.game.sounds["death_self"]) self.game.lives -= 1 self.frozen = True self.death_timer = DEATH_TIME
def respond_to_push(self, direction: Vector2): """Respond to a push by moving in a direction if free to do so or breaking. Args: direction: direction of attempted push - determines movement direction. """ play_sound(self.game.sounds["swoosh"]) hits = pg.sprite.spritecollide(self, self.game.blocks, False, pg.sprite.collide_rect_ratio(1.1)) hits += pg.sprite.spritecollide(self, self.game.walls, False, pg.sprite.collide_rect_ratio(1.1)) blocking = [ hit for hit in hits if is_actor_neighbour_in_direction(self, hit, direction) ] if not blocking: self.vel = BLOCK_SPEED * direction self.game.blocks.remove(self) self.game.moving_blocks.add(self) else: self.blocked_push_response()
def die_and_respawn(self, score_multiplier: int = 1) -> None: """Record death and add score to the player before respawning. Args: score_multiplier: Multiply the score added by this factor. """ play_sound(self.game.sounds["death_enemy"]) added_score = self.point_value * score_multiplier self.game.score += added_score score_marker = ScoreMarker(self.point_value, x=self.rect.x, y=self.rect.y) self.game.all_sprites.add(score_marker) self.deaths += 1 self.set_position(self.starting_x, self.starting_y) self.respawn_timer = RESPAWN_IMMUNITY self.stopped_by = self.initial_stopped_by
def respond_to_push(self, direction): play_sound(self.game.sounds['electric'])