"""
collisions.py - collision checks.. or what else did you thing!?
"""

import common
import pygame

# main check routine
def check():

    # Player first
    if common.player.alive > 0:
        collide = common.player.rect.colliderect

        for x in common.enemies+common.shots_enemy+common.misc_harmful:
            if collide(x.rect):
                common.player.gotHit(x)
                x.kill()

        for x in common.misc_goodies:
            if collide(x.rect):
                common.player.gotGoodie(x)
                x.kill()

    # Now check enemies
    for x in common.enemies:
        collide = x.rect.colliderect
        for y in common.shots_player:
            if collide(y.rect):
                x.gotHit(y)
                y.kill()
                if x.alive <= 0: break # already dead
                
        for y in common.misc_harmful:
            if collide(y.rect):
                x.gotHit(y)
                y.kill()
                if x.alive <= 0: break # already dead

