End a game by either time up or you win

csd-unit-3-lesson-22

#1

A student is trying to make a game that ends when either the timer runs out or you win. We can get one or the other to work - but not both at the same time. Any help is appreciated!

Elaine


#2

I think I found it under another topics - thanks to Josh. Use a variable to check the World.seconds along with his gameOver variable.

function draw() {
background(“white”);
textSize(50);
textAlign(CENTER, CENTER);

var time = 10 - World.seconds;
if (time > 0) {
text(time, 200, 200);
} else {
text(“Time’s Up!”, 200, 200);
}
}