screens/game_screen.py
def check_projectile_collision(self, projectile):
        """ Checks if all types of collisions here. """
        bg_collisions = pygame.sprite.spritecollide(projectile, self.background_collisions, False)
        enemy_collisions = pygame.sprite.spritecollide(projectile, self.enemy_group, False)
        player_collision = pygame.sprite.spritecollide(projectile, self.player_group, False)

        if player_collision:
            for player in player_collision:
                if projectile.rect.right > player.rect.left or projectile.rect.left < player.rect.right:
                    player.get_smaller()

        if enemy_collisions:
            for enemies in enemy_collisions:
                if enemies.name == "piranhaplant":
                    self.death_group.add(enemies)
                elif projectile.rect.right > enemies.rect.left + 20 or projectile.rect.left < enemies.rect.right - 20:
                    enemies.state = self.hub.HIT
                    enemies.kill()
                    self.death_group.add(enemies)

        if bg_collisions:
            for collision in bg_collisions:
                # Hits ground
                if projectile.rect.bottom < collision.rect.top + 20:
                    projectile.rect.bottom = collision.rect.top - 5
                # Hit side walls
                elif projectile.rect.right > collision.rect.left + 20\
                        or projectile.rect.left < collision.rect.right - 20:
                    # Checks if player is not on top
                    if projectile.rect.bottom > collision.rect.top:
                        if projectile.name == "shell":
                            projectile.flip_direction()
                        # enemy.rect.bottom = enemy.rect.bottom - enemy.gravity
 Checks if all types of collisions here. 
Checks if all types of collisions here.
Checks if all types of collisions here .
def check_projectile_collision(self, projectile):
        bg_collisions = pygame.sprite.spritecollide(projectile, self.background_collisions, False)
        enemy_collisions = pygame.sprite.spritecollide(projectile, self.enemy_group, False)
        player_collision = pygame.sprite.spritecollide(projectile, self.player_group, False)
        if player_collision:
            for player in player_collision:
                if projectile.rect.right > player.rect.left or projectile.rect.left < player.rect.right:
                    player.get_smaller()
        if enemy_collisions:
            for enemies in enemy_collisions:
                if enemies.name == "piranhaplant":
                    self.death_group.add(enemies)
                elif projectile.rect.right > enemies.rect.left + 20 or projectile.rect.left < enemies.rect.right - 20:
                    enemies.state = self.hub.HIT
                    enemies.kill()
                    self.death_group.add(enemies)
        if bg_collisions:
            for collision in bg_collisions:
                if projectile.rect.bottom < collision.rect.top + 20:
                    projectile.rect.bottom = collision.rect.top - 5
                elif projectile.rect.right > collision.rect.left + 20\
                        or projectile.rect.left < collision.rect.right - 20:
                    if projectile.rect.bottom > collision.rect.top:
                        if projectile.name == "shell":
                            projectile.flip_direction()
def check_projectile_collision ( self , projectile ) : bg_collisions = pygame . sprite . spritecollide ( projectile , self . background_collisions , False ) enemy_collisions = pygame . sprite . spritecollide ( projectile , self . enemy_group , False ) player_collision = pygame . sprite . spritecollide ( projectile , self . player_group , False ) if player_collision : for player in player_collision : if projectile . rect . right > player . rect . left or projectile . rect . left < player . rect . right : player . get_smaller ( ) if enemy_collisions : for enemies in enemy_collisions : if enemies . name == "piranhaplant" : self . death_group . add ( enemies ) elif projectile . rect . right > enemies . rect . left + 20 or projectile . rect . left < enemies . rect . right - 20 : enemies . state = self . hub . HIT enemies . kill ( ) self . death_group . add ( enemies ) if bg_collisions : for collision in bg_collisions : if projectile . rect . bottom < collision . rect . top + 20 : projectile . rect . bottom = collision . rect . top - 5 elif projectile . rect . right > collision . rect . left + 20 or projectile . rect . left < collision . rect . right - 20 : if projectile . rect . bottom > collision . rect . top : if projectile . name == "shell" : projectile . flip_direction ( )
Checks if all types of collisions here.
Checks if all types of collisions here .
""" Checks if all types of collisions here. """ # Hits ground # Hit side walls # Checks if player is not on top # enemy.rect.bottom = enemy.rect.bottom - enemy.gravity
self
projectile