Skip to content

Commit

Permalink
Merge pull request #29 from simon-tiger/patch-1
Browse files Browse the repository at this point in the history
Having the game end when you hit
  • Loading branch information
shiffman authored Mar 13, 2018
2 parents a085c5e + 9f50432 commit 476fb17
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
// Code for: https://youtu.be/cXgA1d_E-jY

var bird;
var pipes = [];
var pipes;
var parallax = 0.8;
var score = 0;
var maxScore = 0;
var birdIcon;
var pipeBodySprite;
var pipePeakSprite;
var bgImg;
var bgX = 0;
var bgX;
var gameisover = false;

function preload() {
pipeBodySprite = loadImage("./graphics/pipe_body.png");
Expand All @@ -23,8 +24,7 @@ function preload() {

function setup() {
createCanvas(600, 600);
bird = new Bird();
pipes.push(new Pipe());
reset();
}

function draw() {
Expand Down Expand Up @@ -71,6 +71,10 @@ function draw() {
}

showScores();

if (gameisover) {
noLoop();
}
}

function showScores() {
Expand All @@ -85,7 +89,16 @@ function gameover() {
text("HIT", width / 2, height / 2);
maxScore = max(score, maxScore);
score = 0;
gameisover = true;
}

function reset() {
bgX = 0;
pipes = [];
bird = new Bird();
pipes.push(new Pipe());
}

function keyPressed() {
if (key == " ") {
bird.up();
Expand Down

0 comments on commit 476fb17

Please sign in to comment.