In that case, I think I see why the function always returns false.
Lines 18, 19:
1 2
|
if(y > bottom) // if it's already above the brick no collision
return false;
|
Since y increases downward, y > bottom is below the brick, not above it.
If the test on line 18 is failed (ie y <= bottom ) then execution may get to line 25, where the same test is repeated
if( x_ > left && x_ < right && bottom < y)
Note: bottom < y is the same condition as y > bottom. Line 28 can never be reached.
I haven't tested your code but I think the concept won't work well. Your equation of a line produces the path which the ball will follow. The variable x_ is where the ball would be if its y position was at the bottom of the brick, so the test will return true even if the ball is currently well below the brick. A collision is detected if the ball will
ever strike the brick.
EDIT: I have my own ball and brick classes written for a blockout type game. It works well and even handles corner strikes (ball striking a brick corner) in addition to face strikes. I let the ball do the collision testing. I'd be happy to share it with you if you like. Unfortunately, it's dependent on other classes written to support it (2d vector and 2d matrix for working with coordinate transformations).
I've noted though that most people don't want to see other peoples code, they want to figure it out themselves. I totally understand that - I operate that way myself.