Catcher game (game over)

How do i make my code so that if you dont catch something and it hits the ground it will reset? So it will start a new game and say like game over?
Can some help me?
Thanks

Catcher myCatcher;
Ball[] fallingBall;

void setup() {
size(800, 800);
frameRate(25);
myCatcher = new Catcher();
smooth();

fallingBall = new Ball[17];
fallingBall[0] = new Ball();
fallingBall[1] = new Ball();
fallingBall[2] = new Ball();
fallingBall[3] = new Ball();
fallingBall[4] = new Ball();
fallingBall[5] = new Ball();
fallingBall[6] = new Ball();
fallingBall[7] = new Ball();
fallingBall[8] = new Ball();
fallingBall[9] = new Ball();
fallingBall[10] = new Ball();
fallingBall[11] = new Ball();
fallingBall[12] = new Ball();
fallingBall[13] = new Ball();
fallingBall[14] = new Ball();
fallingBall[15] = new Ball();
fallingBall[16] = new Ball();
}

void draw() {
int a;
for (a = 0; a < 17; a++) {
fallingBall[a].display();
fallingBall[a].fall();

if ((abs(mouseY - fallingBall[a].bodyY) < 20) && (abs(mouseX - fallingBall[a].bodyX) < 20)) {
 fallingBall[a].caught();
  println(a + "caught");
}

}
myCatcher.display();
}

class Ball {
float bodyX;
float bodyY;
float i;
float s;
float d;
float speed;
float opacity;
float bodyR;
//float outlineRed;
//float outlineGreen;
float bodyColor;
boolean intersect;

Ball (){
bodyX = int(random(width));
bodyY = int(random(height/2));
i= random(23, 27);
s= random(28, 31);
d= random(8, 11);
bodyR = random(30, 40);
speed = random(1, 3);
opacity = 200;
//outlineRed = random(80, 255);
//outlineGreen = random(0, 180);
bodyColor = random(0, 40);
}

void display(){
ellipseMode(CENTER);
rectMode(CENTER);

//ball
stroke(100, 100, 0);
fill(bodyColor);
ellipse(bodyX, bodyY, bodyR, bodyR);

}

void fall(){
if (bodyY > 820){
bodyY = random(-40, -10);
bodyX = random(width);
opacity = 200;

}
else {
bodyY+= speed;
}
}

// If the spider is caught
void caught() {
bodyY = 820;
opacity = 0;

}
}

class Catcher{
float r; //radius
float x = mouseX;
float y = mouseY;

Catcher(){
r = 20;
}

void display(){
stroke(0);
fill(150);
ellipse(mouseX, mouseY, r, r);
}
}

please format your code posting by pasting it into the

</> code button

of the editor header menu ( context name: Preformatted text )
it looks like
```
type or paste code here
```

also can use the ``` manually above and below your code.

thank you.


why you double post?


you mean,
if inside

class Ball

method

void fall() {

the variable hits bottom of canvas?

if ( bodyY >= height ) {
  // do something
}
1 Like