well if you have a game where there is fixed boundaries like in a pong game the ball can never be any further than let's say 500 so it's enough to check if ballx > 500 than collide

but if there is an obstacle it's not that easy. (sorry I will explain later, my pc is about to crash... )