Another if statement will check to see if the Blue and Red ball are within a certain distance of each other. This function will check to see if the x and y position of the BLUE ball is less than 20 from the x and y position of the RED ball. If so the RED ball will move to a random x and y of 70. The score will increase by 1 and the speed will increase by 1.
Another if statement will check to see the Blue Ball and Green Rectangle x and y are within 20 of each other. If so, the lives will decrease by 1 and the rectangle will go to a random x and y of 30.
if(Math.abs(xBlue-xRed) < 20 && Math.abs(yBlue-yRed) < 20)
{
yRed=int (random(70));
xRed=int (random(70));
score++;
speed++;
}
}
{
if(Math.abs(xBlue-x) < 20 && Math.abs(yBlue-y) < 20)
{
x=(int) random(0, 400);
y=30;
lives--;
}```