First version of the collision detection function (not yet tested)