# When ellipse hit the rect

**URL:** <https://discourse.processing.org/t/when-ellipse-hit-the-rect/11733>\
**Category:** Coding Questions\
**Created:** [May 31, 2019, 10:31am UTC](https://discourse.processing.org/t/when-ellipse-hit-the-rect/11733 "2019-05-31T10:31:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@Nick1](https://discourse.processing.org/u/Nick1)\
**Post date:** [May 31, 2019, 10:31am UTC](https://discourse.processing.org/t/when-ellipse-hit-the-rect/11733/1 "2019-05-31T10:31:06Z")

</div>

Hey,  
I want when my ellipse hit my rect then i want that the ellipse start above another time. But i dont know how to do that.  
Thanks for help

```auto
PImage klo, kacke;
int x;
int [] KackeX;
int [] KackeY;
int [] speedX;
int [] speedY;
boolean starten, gameover;
int batX= 600;
int batY= 800;

void setup()
{
  size(800, 1000);
  orientation(PORTRAIT);
  background(0);
  klo=loadImage("klo.png");
  kacke=loadImage("kacke.png");
  //x=((random(600));
  KackeX = new int[20];
  KackeY = new int[20];
  speedX = new int[20];
  speedY = new int[20];
  gameover=false;
  starten=true;
 
  for (int i=0; i<20; i=i+1)
  {
    KackeX[i]=int(random(800)+100);
    speedY[i]=5;
    KackeY[i]=int(random(-800));
    speedX[i]=1;
  }
}

void draw()
{
  fill(250, 0, 0);
  rect(0, 0, width, height);
 
  rect(batX, batY, 100, 170);
  
  for (int i=0; i<20; i=i+1)
  {
    ellipse( KackeX[i], KackeY[i], 50, 50);
    KackeX[i]= KackeX[i];
    KackeY[i]= KackeY[i]+speedY[i];

  
    if (KackeY[i]>1000)
    {
      background(0);
      gameover=true;
      starten=false;
    }
   

if (KackeY[i]>880 && KackeY[i]>batY && KackeY[i]<batX+170) // Treffer auf Schläger
{
speedY[i]=-3;
}
  }
}

void mousePressed()
{
  println(mouseX,mouseY);
}
void mouseMoved()
{
  batX= mouseX;
  if(batX>700)
  {
   batX=700;
  }
}

```

---

<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:** [June 5, 2019, 4:15am UTC](https://discourse.processing.org/t/when-ellipse-hit-the-rect/11733/2 "2019-06-05T04:15:19Z")

</div>

> [@Nick1](#):
>
> when my ellipse hit my rect

Here is circle-rect collision, explained. Note: not any ellipse, just circle. General ellipse is much harder.

> **[Collision Detection](http://www.jeffreythompson.org/collision-detection/circle-rect.php)**
>
> An online book about collision detection using Processing.

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [June 5, 2019, 4:44pm UTC](https://discourse.processing.org/t/when-ellipse-hit-the-rect/11733/3 "2019-06-05T16:44:05Z")

</div>

for circles,

```auto
if(circle.x+circle.radius > square.x && circle.x+circle.radius > square.x + square.width && circle.y + circle.radius > square.y){
  // run code;
}

```
