From dc72baa2e376fa1d4d7b15be71f44893bdb412c1 Mon Sep 17 00:00:00 2001 From: kzeer Date: Fri, 19 Nov 2021 11:59:55 -0500 Subject: [PATCH 1/5] resolved issue #273 game over without touching any object by modifying flapping.js isOverlap to add half of width/height to midpoint --- javascript/flapping.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/javascript/flapping.js b/javascript/flapping.js index 3822beb..3afd44f 100644 --- a/javascript/flapping.js +++ b/javascript/flapping.js @@ -148,10 +148,10 @@ function getCenteredrect(rect){ function isOverlap(e1, e2) { rect1 = getCenteredrect(e1); rect2 = getCenteredrect(e2); - if (rect1.x < rect2.x + rect2.width && - rect1.x + rect1.width > rect2.x && - rect1.y < rect2.y + rect2.height && - rect1.height + rect1.y > rect2.y) + if (rect1.x < rect2.x + rect2.width/2 && + rect1.x + rect1.width/2 > rect2.x && + rect1.y < rect2.y + rect2.height/2 && + rect1.height/2 + rect1.y > rect2.y) return true; else return false; } From b10d4f7cca1a52b7f12ead034636754b7c314fec Mon Sep 17 00:00:00 2001 From: kzeer Date: Thu, 2 Dec 2021 21:16:51 -0500 Subject: [PATCH 2/5] Printing distance in game over popup --- javascript/flapping.js | 5 ++++- javascript/score.js | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/javascript/flapping.js b/javascript/flapping.js index 3afd44f..4a0f4c9 100644 --- a/javascript/flapping.js +++ b/javascript/flapping.js @@ -6,6 +6,7 @@ function Flappy(layerName) { var me = this; this.action = new Action(function(){me.fly()}, function(){me.started()}); document.onmousedown = function () { me.flap() }; + this.myDist = 0; } Flappy.prototype = { @@ -52,6 +53,8 @@ Flappy.prototype = { }, checkCollision : function() { +// updateDistance(); + this.myDist = this.myDist + 1; var flappy_rect = this.layer.getBoundingClientRect(); for (i = 0; i < 3; i++) { if (i >= obstacles.length) @@ -68,7 +71,7 @@ Flappy.prototype = { } else { var gameOverSound = new Audio("../flappy-svg/Sounds/GameOver.mp3"); gameOverSound.play(); - alert('Game Over :( Final Score: ' + Number(document.getElementById("tspan17169").innerHTML)); + alert('Game Over :( Final Score: ' + Number(document.getElementById("tspan17169").innerHTML) + ', Distance: ' + this.myDist); } if (c || o_rect.right < flappy_rect.left) diff --git a/javascript/score.js b/javascript/score.js index bffbf1c..32bb622 100644 --- a/javascript/score.js +++ b/javascript/score.js @@ -3,3 +3,9 @@ function updateScore(){ var score = Number(score_element.innerHTML); score_element.innerHTML = score+1; } + +//function updateDistance(){ +// var distance_element = document.getElementById("distanceElement"); +// var distance = Number(distance_element.innerHTML); +// distance_element.innerHTML = distance+1; +//} From 2b21458dec71b8e45bc93d27d97b8d267b5213be Mon Sep 17 00:00:00 2001 From: kzeer Date: Wed, 8 Dec 2021 12:42:05 -0500 Subject: [PATCH 3/5] distance counter displaying and incrementing over start screen --- flappy.svg | 33 +++++++++++++++++++++++++++++++++ javascript/flapping.js | 2 +- javascript/score.js | 10 +++++----- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/flappy.svg b/flappy.svg index f1b78a7..c924df7 100644 --- a/flappy.svg +++ b/flappy.svg @@ -64684,6 +64684,39 @@ AAAASUVORK5CYII= id="tspan17169">0 + + + + + + + Distance: + + + + 0 + + + + + Date: Wed, 8 Dec 2021 12:54:06 -0500 Subject: [PATCH 4/5] distance counter consistent for banner and popup --- javascript/flapping.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/javascript/flapping.js b/javascript/flapping.js index 2eff10a..9f645c8 100644 --- a/javascript/flapping.js +++ b/javascript/flapping.js @@ -6,7 +6,6 @@ function Flappy(layerName) { var me = this; this.action = new Action(function(){me.fly()}, function(){me.started()}); document.onmousedown = function () { me.flap() }; - this.myDist = 0; } Flappy.prototype = { @@ -54,7 +53,6 @@ Flappy.prototype = { checkCollision : function() { updateDistance(); - this.myDist = this.myDist + 1; var flappy_rect = this.layer.getBoundingClientRect(); for (i = 0; i < 3; i++) { if (i >= obstacles.length) @@ -71,7 +69,7 @@ Flappy.prototype = { } else { var gameOverSound = new Audio("../flappy-svg/Sounds/GameOver.mp3"); gameOverSound.play(); - alert('Game Over :( Final Score: ' + Number(document.getElementById("tspan17169").innerHTML) + ', Distance: ' + this.myDist); + alert('Game Over :( Final Score: ' + Number(document.getElementById("tspan17169").innerHTML) + ', Distance: ' + Number(document.getElementById("tspan_distance").innerHTML)); } if (c || o_rect.right < flappy_rect.left) From 777c6c0702e800b9fef0616794a16312a7312358 Mon Sep 17 00:00:00 2001 From: kzeer Date: Wed, 8 Dec 2021 16:32:18 -0500 Subject: [PATCH 5/5] distance banner only displaying when game started --- flappy.svg | 6 +++++- javascript/start_screen.js | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/flappy.svg b/flappy.svg index c924df7..6b45736 100644 --- a/flappy.svg +++ b/flappy.svg @@ -64687,7 +64687,11 @@ AAAASUVORK5CYII= - +