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

**URL:** <https://discourse.processing.org/t/do-these-seem-right-cant-seem-to-make-it-work/24544>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [October 12, 2020, 2:18pm UTC](https://discourse.processing.org/t/do-these-seem-right-cant-seem-to-make-it-work/24544 "2020-10-12T14:18:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thughes](https://avatars.discourse-cdn.com/v4/letter/t/0ea827/32.png) [@thughes](https://discourse.processing.org/u/thughes)\
**Post date:** [October 12, 2020, 2:18pm UTC](https://discourse.processing.org/t/do-these-seem-right-cant-seem-to-make-it-work/24544/1 "2020-10-12T14:18:06Z")

</div>

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.

````auto
 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--;
  }```
````

---

<div class="post-metadata">

**Author:** ![thughes](https://avatars.discourse-cdn.com/v4/letter/t/0ea827/32.png) [@thughes](https://discourse.processing.org/u/thughes)\
**Post date:** [October 12, 2020, 2:27pm UTC](https://discourse.processing.org/t/do-these-seem-right-cant-seem-to-make-it-work/24544/2 "2020-10-12T14:27:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 12, 2020, 2:28pm UTC](https://discourse.processing.org/t/do-these-seem-right-cant-seem-to-make-it-work/24544/3 "2020-10-12T14:28:41Z")

</div>

> [@thughes](#):
>
> 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

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

> [@thughes](#):
>
> the rectangle will go to a random x and y of 30.

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

---

<div class="post-metadata">

**Author:** ![thughes](https://avatars.discourse-cdn.com/v4/letter/t/0ea827/32.png) [@thughes](https://discourse.processing.org/u/thughes)\
**Post date:** [October 12, 2020, 3:00pm UTC](https://discourse.processing.org/t/do-these-seem-right-cant-seem-to-make-it-work/24544/4 "2020-10-12T15:00:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 12, 2020, 3:24pm UTC](https://discourse.processing.org/t/do-these-seem-right-cant-seem-to-make-it-work/24544/5 "2020-10-12T15:24:35Z")

</div>

> [@thughes](#):
>
> check to see the Blue Ball and Green Rectangle x and y are within 20 of each other.

Do you mean this?

Use dist() too
