1
Graphics / SFML 2.0 Getting ball to collide with paddle in a pong game
« on: June 24, 2012, 06:23:13 am »
Hi everybody, first time poster here. I am trying to make a pong type game and I am having trouble with getting the ball that i have bouncing around to collide with the paddle correctly. I have seen a few methods online that I must not be implementing right, the ball with either go through the paddle and bounce back a little later, strange movement etc. If anyone can look at my code and give some suggestions that would be great. Just the snippet of the if statement, xMovement is a float var.
if(ballSprite.GetPosition().x + ballSprite.GetScale().x + ballSprite.GetPosition().y + ballSprite.GetScale().y <= bluePaddleSprite.GetPosition().x + bluePaddleSprite.GetScale().x + bluePaddleSprite.GetPosition().y + bluePaddleSprite.GetScale().y)
{
xMovement = -xMovement;
}
{
xMovement = -xMovement;
}