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;
}