Skip to content

Commit

Permalink
Merge pull request #42 from DaGuT/keygo
Browse files Browse the repository at this point in the history
GAMEOVER with pause and restart on space press (+ mobile support)
  • Loading branch information
Versatilus authored Mar 26, 2018
2 parents 0abb4e5 + 40a6165 commit 51e9207
Showing 1 changed file with 14 additions and 3 deletions.
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();
}

0 comments on commit 51e9207

Please sign in to comment.