# Följande kod skrevs under lektionen och är inte ideal med avseende
# på kommentering etc

import math

class CollisionChecker (object):
    def __init__ (self, width, height):
        self.width = width
        self.height = height
        self.objects = []
    
    def add (self, obj):
        self.objects.append (obj)

    def hasCollided (self, obj):
        if obj.x < obj.radius or self.width - obj.x < obj.radius \
            or obj.y < obj.radius or self.height - obj.y < obj.radius:
            return True
        for other in self.objects:
            if other == obj:
                continue
            if self.distance (obj, other) < obj.radius + other.radius:
                return True
        return False

    def distance (self, obj1, obj2):
        dx = obj1.x - obj2.x
        dy = obj1.y - obj2.y
        return math.sqrt (dx * dx + dy * dy)
