I need help with a life counter ending the game. I need it to end the program when the lives hit 0

//START SCREEN
int stateWaitBeforeProgram = 0;
int stateNormalProgram = 1;
int state = stateWaitBeforeProgram;

//TIMER
class Timer {
  int time;
  int duration;
  
  Timer() {
    duration = 100;
    reset();
  }
  
  void reset() {
    time = millis() + duration;
  }

  boolean alarm() {
    if ( millis() > time ) {
      time = millis() + duration;
      return true;
    }
    return false;
  }
}

//VARIABLES
float s; //size of circles
PVector targetPosition; // position of target
color c; //colour of circles
int score = 0; //score
int miss = 0; //misses
int lives = 17; //lives
boolean gameOver = false;
Timer timer = new Timer();
PImage img;

void setup() {
  size(700, 500);
  timer.duration = 800; //changes the circle every 0.8 seconds
  newEllipse(); // Makes initial circle.
	img = loadImage("missed shot.png");
}

void newEllipse() {
  s = random(10, 50); //random size between 10-50
  targetPosition = new PVector(random(s/2, width - s/2), random(s/2, height - s/2)); // random position
  c = color( random(255), random(255), random(255) ); //random colour
  timer.reset(); //resets timer with each circle
}

void displayGameOverScreen() { //game over screen with score.
	background(100);
	fill(255);
	textSize(20);
	textAlign(CENTER,CENTER)
	text('GAME OVER YOUR SCORE IS: ' + score, width / 2, height / 2);
}

void live_manager() { //if lives = 0 game ends
  if (lives <= 0)
    gameOver = true;
}

void draw() {
	if (state == stateWaitBeforeProgram) { //START SCREEN //pauses until you click the screen
	textSize(50);
	textAlign(CENTER.BOTTOM);
	text ('"WELCOME"',210,220);
	textAlign(CENTER.CENTER);
  text ('"CLICK TO BEGIN"',140,270); 
}
	else {
		if (gameOver == false){
		background(100); //bg
		fill(255); //white text
		text("SCORE: " + str(score), 620, 20); //score.
		text("MISSED: " + str(miss), 20, 20); //misses.
		text("LIVES: " + str(lives), 20, 50); //lives.
		fill(c); // random colour circles
		ellipse(targetPosition.x, targetPosition.y, s, s); //placing the circle at the random position.
 		if ( timer.alarm() ) { //ran out of time.
			miss += 1; //+1 miss if you cant hit the circle due to time.
			lives--; //-1 life if you cant hit the circle due to time.
			image(img,0,0); //red miss image if you cant hit circle due to time.
			newEllipse(); //spawns a new circle.
		}
}else{ 
		gameOver == true;
		noLoop();
		displayGameOverScreen();
	}
	}
}

void mousePressed() { //START SCREEN
 
if (state == stateWaitBeforeProgram) {
 state =stateNormalProgram ;
}
else {
}
} 

void mouseClicked() {
	if (overEllipse()) { //allows click on circle.
		score += 1; //+1 if user clicks on circle.
		newEllipse(); //spawns new circle.
	} else { //if you miss.
		miss += 1; //+1 miss when the user clicks at random.
		lives--; //-1 life when the user clicks at random.
		image(img,0,0) //red miss image when user clicks at random.
		}
}
	
boolean overEllipse() {
	PVector mousePosition = new PVector(mouseX, mouseY); //allows circle to be hit
	return mousePosition.dist(targetPosition) < s/2; //circle hitbox
}

You already have a function that’s checking for this situation.

But this function is never called. As a first step, call this function when the lives counter changes.

Then change the function so that, instead of causeing the Game Over screen to happen, it causes the program to end. You can do that by having live_manager() call the exit() function instead of setting gameOver to ture.

1 Like