# Do these seem right? can't seem to make it work

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--;
}`````````
1 Like

The balls are supposed to collide and move to a different position, increase score, decrease lives…all they do is go right over each other

for distance you can use the command dist() also - see reference.

I think they want random value for y too. But who knows.

okay…i think i have it right…but can’t get the the balls to collide

Do you mean this?

Use dist() too