# When ellipse hit the rect

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

``````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);
//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;
}
}
``````

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

for circles,

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