Advanced collision detection
Kressilac
To start, I would say that the ball either hits one side of the box, or a corner. If it his a side, then it should reflect off the side at an angle opposite of the incoming angle, reletive to the side. If it hits a corner, all you need to do is reverse its x, and y velocities.
To determine what side(s) it hit, first I would find the point on the ball that is closest to the center of the box. And then I would use that point to do some simple tests.
Here is some 1/2 Pseudo code:
bx, and by are the point on the ball closest to the box.
brect is the boxes RECT.
if (by < brect.top)
{
if(bx < brect.left)
{
ball hit at top left corner
}
else if(bx > brect.right)
{
ball hit top right corner
}
else
{
ball hit just top edge
}
}
else if(by > brect.bottom)
{
do same type of thing as above
}
else if(bx < brect.left)
{
do same type of thing as above
}
else if(bx > brect.right)
{
do same type of thing as above
}
there, obviously this could be optimized, and integrated into your basic collition code, but this is the basic idea.
If this doesn't make sense, or you have questions, email me at Pseudo_me@email.com.
Pseudo