ARTICLE AD BOX
This is for the animation of the ball (im doing the pong game). Honestly, I don't know how to code and have been mainly following the tutorial, but I've checked like 10 times and I'm sure I haven't gotten it wrong. I can't ask anyone else, SOS!
This code is mostly to make the ball bounce off the corners.
var ball = {
x: totalWidth / 2 - 5,
y: totalHeight / 2 - 5,
xSpeed: 3,
ySpeed: 3
};
if (ball.y > totalHeight - 10) {
ball.ySpeed = -ball.ySpeed;
}
if ball.y < 0) {
ball.ySpeed = -ball.ySpeed;
}
if (ball.x > totalWidth - 30 &&
ball.y > player2.y &&
ball.y < player2.y + 80)
{
ball.xSpeed = -ball.xSpeed;
} else if (ball.x > totalWidth - 30)
if (ball.x < 20 &&
ball.y > player1.y + 80) {
ball.xSpeed = -ball.xSpeed;
}
