Skip to content

Commit 6a1feeb

Browse files
authored
Merge pull request #39 from DaGuT/gameoverfix
gameover now RESTARTS if you hit pipe
2 parents e729cec + 265a618 commit 6a1feeb

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

sketch.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var pipeBodySprite;
1919
var pipePeakSprite;
2020
var bgImg;
2121
var bgX;
22-
var gameisover = false;
22+
var gameoverFrame=0;
2323

2424
var touched = false;
2525
var prevTouched = touched;
@@ -75,7 +75,7 @@ function draw() {
7575
bird.update();
7676
bird.show();
7777

78-
if (frameCount % 150 === 0) {
78+
if ((frameCount-gameoverFrame) % 150 == 0) {
7979
pipes.push(new Pipe());
8080
}
8181

@@ -97,9 +97,6 @@ function draw() {
9797
prevTouched = touched;
9898

9999

100-
if (gameisover) {
101-
noLoop();
102-
}
103100
}
104101

105102
function showScores() {
@@ -113,14 +110,15 @@ function gameover() {
113110
text('HIT', width / 2, height / 2);
114111
maxScore = max(score, maxScore);
115112
score = 0;
116-
gameisover = true;
113+
reset();
117114
}
118115

119116
function reset() {
120117
bgX = 0;
121118
pipes = [];
122119
bird = new Bird();
123120
pipes.push(new Pipe());
121+
gameoverFrame=frameCount-1;
124122
}
125123

126124
function keyPressed() {

0 commit comments

Comments
 (0)