Can you thoroughly explain what what the variables x1, y1, x2, and y2 stand for? Does "pi" stand for 3.141592....?
By the way, does anyone have a good pixel-perfect collision detection algorithm that is compatible with CDX and MSVC++ 5.0?
Can you thoroughly explain what what the variables x1, y1, x2, and y2 stand for? Does "pi" stand for 3.141592....?
By the way, does anyone have a good pixel-perfect collision detection algorithm that is compatible with CDX and MSVC++ 5.0?
However, if you are detecting collision between two circles all you have to do is find the distance between the centers of the two. If that distance is less than or equal two the sum of the two radii then they are in contact.
Distance Formula:
D = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) )
(derived from a^2 + b^2 = c^2)
Also, about the angle of incidence of the puck on the paddle. If your paddle is perfectly rectangular then the puck will bounce off in the same direction irregardless where it hits the paddle.
Here is the coordinate plane I used:
0,0----------------50,0 (X axis)
|
|
|
|
|
0,50
(Y axis)
Paddle is the left most coordinate of the
paddle. To get the sections, all I had to
was add 9 for each section, because each section was 9 pixels long.
ball_velocity_x is the speed of the ball on the x axis
ball_velocity_y is the speed of the ball on the y axis
paddle_left = paddle + 18;
// Left of paddle, for lower paddle
if ((ball_x >= paddle && ball_x <= paddle_left) && (ball_y > paddle_y))
{
ball_velocity_x = .4;
ball_velocity_y = 2.4;
}
Here are the angles I used for my paddle:
Left = ball_velocity_x = -.4
ball_veloctiy_y = -2.4
Left Center = ball_velocity_x = -1
ball_velocity_y = -1
Center = ball_velocity_x = 0
ball_velocity_y = -1
Right Center = ball_velocity_x = 1
ball_velocity_y = -1
Right = ball_velocity_x = .4
ball_velocity_y = -2.4
For the upper paddle I just reversed those velocity settings. I didn't include the centermost left and right areas because I forgot what they were and I don't have my program to look at right now.
If you have any questions about what I just posted please ask. I hope that helped you.