Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GAMEOVER with pause and restart on space press (+ mobile support) #42

Merged
merged 2 commits into from
Mar 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var pipePeakSprite;
var bgImg;
var bgX;
var gameoverFrame=0;
var isOver = false;

var touched = false;
var prevTouched = touched;
Expand Down Expand Up @@ -107,22 +108,32 @@ function showScores() {

function gameover() {
textSize(64);
text('HIT', width / 2, height / 2);
textAlign(CENTER,CENTER);
text('GAMEOVER', width / 2, height / 2);
textAlign(LEFT,BASELINE);
maxScore = max(score, maxScore);
score = 0;
reset();
isOver=true;
noLoop();
}

function reset() {
isOver=false;
score = 0;
bgX = 0;
pipes = [];
bird = new Bird();
pipes.push(new Pipe());
gameoverFrame=frameCount-1;
loop();
}

function keyPressed() {
if (key === ' ') {
bird.up();
if (isOver) reset(); //you can just call reset() in Machinelearning if you die, because you cant simulate keyPress with code.
}
}

function touchStarted() {
if (isOver) reset();
}