Hi @mrporcessing,
as @josephh said, please take time to format your code when you post it ; it is more readable for people who will help you.
Concerning your issue, you have to check if the ball position in X axe exceeds the position of one of your pad :
score1 += 10;
}
if (ball_posX >= pad1X){ // for right pad
score2 += 10;
}
But it seems that doing this, you won’t add only 10 points by winning once, but 70 because, loop goes 7 times before restart.
Your actual conditon restart the game when the middle of the ball exceeds the position of the right pad, whereas the condition of giving point is validated when the corner of the ball exceeds, so the draws loops many times before the middle of ball exceeds it also.
So you can change a little the condition to validate only once the scoring, according to your condition of restart :
if (ball_posX <= 1) { // because you restart the game at ball_posX < 0, so add score the frame just before
score1 += 10;
}
if (ball_posX >= width - ball_size - 1) {// because you restart the game at ball_posX > width - ball_size, so add score the frame just before
score2 += 10;
}
if (ball_posX < 0)||(ball_posX > screenX - ball_size){
// restart game
}