From f86964e5adde187878e9c0a0426779c1d6089b96 Mon Sep 17 00:00:00 2001 From: Simon Tiger Date: Fri, 9 Mar 2018 20:30:42 +0100 Subject: [PATCH 1/2] Having the game end when you hit --- sketch.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sketch.js b/sketch.js index 727b10b..e3ec98b 100644 --- a/sketch.js +++ b/sketch.js @@ -11,6 +11,7 @@ var birdIcon; var pipeBodySprite; var bgImg; var bgX = 0; +var gameisover = false; function preload() { pipeBodySprite = loadImage("./graphics/pipe_body.png"); @@ -68,6 +69,10 @@ function draw() { } showScores(); + + if (gameisover) { + noLoop(); + } } function showScores() { @@ -82,6 +87,7 @@ function gameover() { text("HIT", width / 2, height / 2); maxScore = max(score, maxScore); score = 0; + gameisover = true; } function keyPressed() { if (key == " ") { From f98fd174038a696c49e0384c3ae2ba39dbcc3ede Mon Sep 17 00:00:00 2001 From: Simon Tiger Date: Tue, 13 Mar 2018 11:31:17 +0100 Subject: [PATCH 2/2] Changing to restarting the game --- sketch.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sketch.js b/sketch.js index e3ec98b..1ea6143 100644 --- a/sketch.js +++ b/sketch.js @@ -4,13 +4,13 @@ // Code for: https://youtu.be/cXgA1d_E-jY var bird; -var pipes = []; +var pipes; var score = 0; var maxScore = 0; var birdIcon; var pipeBodySprite; var bgImg; -var bgX = 0; +var bgX; var gameisover = false; function preload() { @@ -21,8 +21,7 @@ function preload() { function setup() { createCanvas(600, 600); - bird = new Bird(); - pipes.push(new Pipe()); + reset(); } function draw() { @@ -89,6 +88,14 @@ function gameover() { score = 0; gameisover = true; } + +function reset() { + bgX = 0; + pipes = []; + bird = new Bird(); + pipes.push(new Pipe()); +} + function keyPressed() { if (key == " ") { bird.up();