Pong collision detection
Posted: May 21st, 2020, 10:34 pm
int BallWidth = xPos + width;
int BallHeight = yPos + height;
if (BallWidth >= PaddleX && xPos <= PaddleX + PaddleWidth &&
BallHeight >= PaddleY && yPos <= PaddleY + PaddleHeight)
{
vx + 1;
BallWidth = PaddleX - 3;
}
if (BallWidth >= PaddleX && xPos <= PaddleX + PaddleWidth &&
BallHeight >= PaddleY && BallHeight <= PaddleY + PaddleHeight)
{
vy - 1;
BallHeight = PaddleY - 3;
}
if (BallWidth >= PaddleX && xPos <= PaddleX + PaddleWidth && yPos <= PaddleY + PaddleHeight && yPos >= PaddleY)
{
vy + 1;
yPos = PaddleY + PaddleHeight + 3;
}
====
Hmmm I can't seem to get the top paddle or the bottom paddle to collide and bounce off correctly. Would someone mind giving me a few pointers in this direction? Thank you!
int BallHeight = yPos + height;
if (BallWidth >= PaddleX && xPos <= PaddleX + PaddleWidth &&
BallHeight >= PaddleY && yPos <= PaddleY + PaddleHeight)
{
vx + 1;
BallWidth = PaddleX - 3;
}
if (BallWidth >= PaddleX && xPos <= PaddleX + PaddleWidth &&
BallHeight >= PaddleY && BallHeight <= PaddleY + PaddleHeight)
{
vy - 1;
BallHeight = PaddleY - 3;
}
if (BallWidth >= PaddleX && xPos <= PaddleX + PaddleWidth && yPos <= PaddleY + PaddleHeight && yPos >= PaddleY)
{
vy + 1;
yPos = PaddleY + PaddleHeight + 3;
}
====
Hmmm I can't seem to get the top paddle or the bottom paddle to collide and bounce off correctly. Would someone mind giving me a few pointers in this direction? Thank you!