screens/game_screen.py
def check_enemy_collision(self, enemy):
        """ Checks the enemy colliding with Pipes"""
        bg_collisions = pygame.sprite.spritecollide(enemy, self.background_collisions, False)
        enemy_collisions = pygame.sprite.spritecollide(enemy, self.enemy_group, False)
        brick_collisions = pygame.sprite.spritecollide(enemy, self.brick_group, False)

        if brick_collisions:
            for brick in brick_collisions:
                if enemy.rect.bottom < brick.rect.top + 25:
                    enemy.rect.bottom = brick.rect.top
                # check if the player hits the left wall
                elif enemy.rect.right < brick.rect.left + 20:
                    enemy.rect.right = brick.rect.left
                    enemy.flip_direction()
                # check if the player hits the right wall
                elif enemy.rect.left > brick.rect.right - 20:
                    enemy.rect.left = brick.rect.right
                    enemy.flip_direction()

                if brick.state == self.hub.BUMPED:
                    enemy.state = self.hub.HIT

        if enemy_collisions:
            for enemies in enemy_collisions:
                if enemy != enemies:
                    if enemy.rect.bottom < enemies.rect.top:
                        enemy.rect.bottom = enemies.rect.top
                    if enemy.rect.right > enemies.rect.left + 20:
                        enemy.rect.right = enemies.rect.left
                        enemy.flip_direction()

                    if enemy.rect.left < enemies.rect.right - 20:
                        enemy.rect.left = enemies.rect.right

        if bg_collisions:
            for collision in bg_collisions:
                # Hits ground
                if enemy.name != "piranhaplant":
                    if enemy.rect.bottom < collision.rect.top + 20:
                        enemy.rect.bottom = collision.rect.top - 5
                    # Hit side walls
                    elif enemy.rect.right > collision.rect.left + 20 or enemy.rect.left < collision.rect.right - 20:
                        # Checks if player is not on top
                        if enemy.rect.bottom > collision.rect.top:
                            enemy.flip_direction()
 Checks the enemy colliding with Pipes
Checks the enemy colliding with Pipes
Checks the enemy colliding with Pipes
def check_enemy_collision(self, enemy):
        bg_collisions = pygame.sprite.spritecollide(enemy, self.background_collisions, False)
        enemy_collisions = pygame.sprite.spritecollide(enemy, self.enemy_group, False)
        brick_collisions = pygame.sprite.spritecollide(enemy, self.brick_group, False)
        if brick_collisions:
            for brick in brick_collisions:
                if enemy.rect.bottom < brick.rect.top + 25:
                    enemy.rect.bottom = brick.rect.top
                elif enemy.rect.right < brick.rect.left + 20:
                    enemy.rect.right = brick.rect.left
                    enemy.flip_direction()
                elif enemy.rect.left > brick.rect.right - 20:
                    enemy.rect.left = brick.rect.right
                    enemy.flip_direction()
                if brick.state == self.hub.BUMPED:
                    enemy.state = self.hub.HIT
        if enemy_collisions:
            for enemies in enemy_collisions:
                if enemy != enemies:
                    if enemy.rect.bottom < enemies.rect.top:
                        enemy.rect.bottom = enemies.rect.top
                    if enemy.rect.right > enemies.rect.left + 20:
                        enemy.rect.right = enemies.rect.left
                        enemy.flip_direction()
                    if enemy.rect.left < enemies.rect.right - 20:
                        enemy.rect.left = enemies.rect.right
        if bg_collisions:
            for collision in bg_collisions:
                if enemy.name != "piranhaplant":
                    if enemy.rect.bottom < collision.rect.top + 20:
                        enemy.rect.bottom = collision.rect.top - 5
                    elif enemy.rect.right > collision.rect.left + 20 or enemy.rect.left < collision.rect.right - 20:
                        if enemy.rect.bottom > collision.rect.top:
                            enemy.flip_direction()
def check_enemy_collision ( self , enemy ) : bg_collisions = pygame . sprite . spritecollide ( enemy , self . background_collisions , False ) enemy_collisions = pygame . sprite . spritecollide ( enemy , self . enemy_group , False ) brick_collisions = pygame . sprite . spritecollide ( enemy , self . brick_group , False ) if brick_collisions : for brick in brick_collisions : if enemy . rect . bottom < brick . rect . top + 25 : enemy . rect . bottom = brick . rect . top elif enemy . rect . right < brick . rect . left + 20 : enemy . rect . right = brick . rect . left enemy . flip_direction ( ) elif enemy . rect . left > brick . rect . right - 20 : enemy . rect . left = brick . rect . right enemy . flip_direction ( ) if brick . state == self . hub . BUMPED : enemy . state = self . hub . HIT if enemy_collisions : for enemies in enemy_collisions : if enemy != enemies : if enemy . rect . bottom < enemies . rect . top : enemy . rect . bottom = enemies . rect . top if enemy . rect . right > enemies . rect . left + 20 : enemy . rect . right = enemies . rect . left enemy . flip_direction ( ) if enemy . rect . left < enemies . rect . right - 20 : enemy . rect . left = enemies . rect . right if bg_collisions : for collision in bg_collisions : if enemy . name != "piranhaplant" : if enemy . rect . bottom < collision . rect . top + 20 : enemy . rect . bottom = collision . rect . top - 5 elif enemy . rect . right > collision . rect . left + 20 or enemy . rect . left < collision . rect . right - 20 : if enemy . rect . bottom > collision . rect . top : enemy . flip_direction ( )
Checks the enemy colliding with Pipes
Checks the enemy colliding with Pipes
""" Checks the enemy colliding with Pipes""" # check if the player hits the left wall # check if the player hits the right wall # Hits ground # Hit side walls # Checks if player is not on top
self
enemy