collision algorithm taken from https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection