# Trying to code a catch game

**URL:** <https://discourse.processing.org/t/trying-to-code-a-catch-game/10137>\
**Category:** Coding Questions\
**Created:** [April 9, 2019, 4:05pm UTC](https://discourse.processing.org/t/trying-to-code-a-catch-game/10137 "2019-04-09T16:05:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gp-gp](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gp-gp](https://discourse.processing.org/u/gp-gp)\
**Post date:** [April 9, 2019, 4:05pm UTC](https://discourse.processing.org/t/trying-to-code-a-catch-game/10137/1 "2019-04-09T16:05:21Z")

</div>

Im trying to code this catch game i p5, and i cant figure out how i can detect the falling objekt with the “basket” i’ve drawn…

hope you guys can help

```auto
let box1_x;
let box1_y;
let box1

let box2_x;
let box2_y;
let box2_w;
let box2;

let score;

function setup() {
  createCanvas(800, 800);
  
  box1_x = 400;
  box1_y = 100;
  box1 = box1_x*box1_y;
  
  
  
  box2_x = mouseX;
  box2_y = 700;
  box2_w = 100;
  box2 = box2_x*box2_y;
  
  
  score = 0;
}

function draw() {
  background(220);
  
  
  //red
  fill(255,0,0)
  rectMode(CENTER)
  rect(mouseX,box2_y,box2_w,50)
  
  
  //green
  fill(0,255,0)
  rectMode(CENTER)
  rect(box1_x,box1_y,25,50)
  //the box is falling
  box1_y += 5;
  
  //get the box back up again
  if (box1_y>box2_y){
    box1_y=0;
  }
  
  if (box2_x>box1_x>box2_w){
    score += 1;
    print(score)
  }
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 9, 2019, 4:11pm UTC](https://discourse.processing.org/t/trying-to-code-a-catch-game/10137/2 "2019-04-09T16:11:31Z")

</div>

[CrHallberg.com/CollisionDetection/Website/rect-rect.html](http://CrHallberg.com/CollisionDetection/Website/rect-rect.html)

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 12, 2019, 4:07pm UTC](https://discourse.processing.org/t/trying-to-code-a-catch-game/10137/3 "2019-04-12T16:07:37Z")

</div>

Hi @gp-gp, hope that the link to the Collision Detection book was helpful to you.

@GoToLoop – interesting, is CrHallberg’s site a translation of Jeff Thompson’s site into JavaScript?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 12, 2019, 4:20pm UTC](https://discourse.processing.org/t/trying-to-code-a-catch-game/10137/4 "2019-04-12T16:20:39Z")

</div>

> <https://github.com/jeffThompson/CollisionDetection/issues/5>
