19) Using Processing to.....
Set a variable to keep score
We can keep check of who is winning by storing each players score in a variable.
Create a new variable, as our scores will be whole numbers, set it to be an int variable.
I will call the variable I am using to score player A’s score score_a.
At the top of your sketch, write..
int right_score = 0;
For the player controlling the Pong bat to the right side of the screen,
we want to be able to increase the score each time the ball touches the far left hand side of the sketch.
In the void draw()
add the line
score_a = score_a + 1
to
if (ball_x < 0 + ball_size / 2) {
pos_neg_x = -1;
}
resulting in..
if (ball_x > 0 + ball_size / 2 ) {
pos_neg_x = -1;
right_score= right_score + 1
}
right_score = right_score + 1 can also be written as right_score++
© Copyright 2026 Paperzz