Fiddle with a quadtree, optimizing a collision engine. Check out the repository here! Dedicated page here.