Coding game: catching coins and avoiding bombs

Okay, so the lives do go down now but the game doesn’t stop when the lives hit 0

//main

int score; //Ergebnisanzeige Variable
int lives = 5;
float x = 100;
float y = 500;
int gefangCoins = 0;

PImage image;

Balken balken; //One Balken object
Timer timer;
Ball[] ball; //An array of ball objects

void setup() {
size(1280, 720);
smooth();
frameRate(30);
textSize(15);

image = loadImage(“PirateIsland.jpg”);

balken = new Balken(20);
ball = new Ball[100]; //Create 1000 spots in the array
timer = new Timer(300);
timer.start();
}

void draw() {
image(image,width,height);
//image(image, 0, 0);
background(image);

// Display the catcher
balken.display(); //Balken anzeige

// Check the timer
if (timer.isFinished()) {
// Deal with coins
ball[gefangCoins] = new Ball(); // Initialize one coin
gefangCoins++; // Increment totalCoins

// If we hit the end of the array
if (gefangCoins >= ball.length) {
  gefangCoins = 0; // Start over
  score = 0;
 
}
timer.start();

}

// Move and display all drops
for (int i = 0; i < gefangCoins; i++ ) {
ball[i].move();
ball[i].display();
if (balken.intersect(ball[i])) {
ball[i].caught();
// score++;
}
}
textSize(15);
text("Score = "+score, 10, 20);
text("Lives = "+lives, 10, 40);

}

//class bar/ship

class Balken {

float xSpeed = 0; //Speed in direction X
float ySpeed = 0; //Speed in direction Y

float r; //Radius
float b, h; //Width and Height
color col; // color
float x, y; // location

PImage image;

Balken(float tempR) {

image = loadImage("ship.png");

b = 150;
h = 150;
r = tempR;
col = color(50, 129, 129);
fill(col);
x = 100;
y = 520;

}

void setLocation(float x1, float y1) { //float tempX/Y
x = x1; //tempX
y = y1; //temp Y
}

void move() {
x -= xSpeed; //Increment x
y += ySpeed; //Increment y

}

void display() {
stroke(9);
fill(col);

if ((keyPressed == true) && (key == CODED)) {
  if (keyCode == LEFT) {
    x-=10;
  } else if (keyCode == RIGHT) {
    x+=10;
  }
}
  image(image, x, y, b, h);
 
}

// A function that returns true or false based on
// if the catcher intersects a raindrop
boolean intersect(Ball d) {
// Calculate distance
float distance = dist(x, y, d.x, d.y);
if((d.x > x && d.x < x+b) && (dist(d.y, 0, y, 0) < 54 || d.y>=y-22))
{
return true;
} else return false;

}
}

//class ball

class Ball {

float x; //X-Koordinate
float y; //Y-Koordinate
float r; // Radius 10

int yDir = 1; //In Welche Richtung geht es?
float y_speed = random(1, 7);

int score = 0; //Ergebnisanzeige Variable
int leben = 5; //Lebensanzeige variable
boolean lost = false; //Anzeige ob man verloren hat oder nicht

color c; // Define color ‘c’

PImage muenze;
PImage bombe;

boolean isCoin ;

Ball() {
muenze = loadImage(“coin.png”);
bombe = loadImage(“Bombe.png”);
muenze.resize(50, 0);
bombe.resize(50, 0);
r = 10; // All coins are the same size
if (random(1) < 0.5)
{
isCoin = true;
} else {
isCoin = false;
}

x = random(width);    // Start with a random x location
y = -r*4;      // Start a little above the window
y_speed = random(1, 3);      // Pick a random speed
c = color(255, 129, 129);    //Color

}

// Move the Ball down
void move() {
// Increment by speed
y+=y_speed;
}

//Check if it hits the bottom
boolean Bodenerreicht() {
//If we go beyond the bottom
if (y > height) {
return true;
} else {
return false;
}
}

void display() { //Display the ball
fill(c);
noStroke();
// image(muenze, x, y);
// image(bombe, x, y);

 if(isCoin)
      image(muenze, x, y);
else 
    image(bombe, x, y);

}

//If the drop is caught
void caught() {
y_speed = 0; //Stop it from moving by setting speed equal to zero
y= -1000; //Set the location to somewhere way off-screen

if(isCoin) 

score++;

 else 

lives–;

}

}

//class timer

class Timer {

int savedTime; // When Timer started
int totalTime; // How long Timer should last

Timer(int tempTotalTime) {
totalTime = tempTotalTime;
}

// Starting the timer
void start() {
// When the timer starts it stores the current time in milliseconds.
savedTime = millis();
}

// The function isFinished() returns true if 5,000 ms have passed.
// The work of the timer is farmed out to this method.
boolean isFinished() {
// Check how much time has passed
int passedTime = millis()- savedTime;
if (passedTime > totalTime) {
return true;
} else {
return false;
}
}
}