Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolved issue #45 distance counter #304

Open
wants to merge 5 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions flappy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 6 additions & 5 deletions javascript/flapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Flappy.prototype = {
},

checkCollision : function() {
updateDistance();
var flappy_rect = this.layer.getBoundingClientRect();
for (i = 0; i < 3; i++) {
if (i >= obstacles.length)
Expand All @@ -68,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));
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)
Expand Down Expand Up @@ -148,10 +149,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;
}
Expand Down
6 changes: 6 additions & 0 deletions javascript/score.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ function updateScore(){
var score = Number(score_element.innerHTML);
score_element.innerHTML = score+1;
}

function updateDistance(){
var distance_element = document.getElementById("tspan_distance");
var distance = Number(distance_element.innerHTML);
distance_element.innerHTML = distance+1;
}
1 change: 1 addition & 0 deletions javascript/start_screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function startGame() {
// this must be configured one mousedown event in the start screen
layerNamed('startscreen').style.display = 'none'; // none = hide layer
layerNamed('score_board').style.display = 'inline';
layerNamed('distance_board').style.display = 'inline';
startFlapping('bird');
startMovingBackgound('background', -7);
startMovingBackgound('cactus', -7);
Expand Down