Game Timer Question

I have created a game similar to pong and at the end I have made a “Game Over” text appear for 5 seconds before the game resets. The problem is, when the game resets, the timer seems to not work anymore. Any ideas on how I can fix this. Below is the code: (the class for timer is separate if it is necessary I can attach it as well)

float ballx;
float bally;

float ballr = 20;

float xspeed = 7;
float yspeed = 4;

float recty = 750;
float rectw = 150;
float recth = 40;

Timer timer;


void setup() {
  size(800,800);
  timer = new Timer(5000);
  timer.start();
  ballx = width*0.5;
  bally = height*0.8;
 
 
}
   

void draw() {
  background(0);
  //ball
  fill(28,200,255);
  ellipse(ballx,bally,40,40);
  ballx=ballx+xspeed;
  bally=bally+yspeed;
  
  fill(255);
  rectMode(CENTER);
  rect(mouseX, recty, rectw, recth, 30);
  
  //boundaries

 if (ballx>width){
    xspeed=-7;
  }
  if (ballx<0){
    xspeed=7;
  }
  
  if (bally<0){
    yspeed=4;
  }
  
  
  if (bally-ballr/2>height) {
    textSize(130);
    text("GAME OVER", 70, 200);
    
    if (timer.isFinished()) {
    reset();
    }
  } else if (ballx>mouseX-rectw/2 && 
    ballx<mouseX+rectw/2 &&
    bally+ballr/2>recty-23 ) {
    yspeed = -random(8,10);
    xspeed = random(-12,14);
  }
}//func 

void reset() {

  ballx=400;
  bally=200;

  xspeed = 7;
  yspeed = 4;
}

New problem just surfaced. When the code first starts the ball spawns super low but after the first game over it spawns right and the game over timer doesn’t work. :frowning:

1 Like

If you play last long enough the timer doesn’t work after the first round either

1 Like

Please avoid duplicate posts

thats my bad i wont do it again. i didnt fell like i had stated my question out well or laid the code out clearly in the first one

1 Like

Don’t worry. Does it work now with the help in the other discussion?

I’m still working on the code but the response was super helpful and the concept is much clearer now.

1 Like

So I’m 99% sure it will work once I finish it

1 Like