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

Added GameOver(Restart button) and score board. #89

Merged
Show file tree
Hide file tree
Changes from 4 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
83 changes: 80 additions & 3 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.
12 changes: 11 additions & 1 deletion javascript/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ function stopMovingBackgound(name) {
background(name).stopMoving();
}

function stopAllBackgrounds(){

var keys = Object.keys(backgrounds);
for (i = 0; i < keys.length; i++){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use backgrounds.length

stopMovingBackgound(keys[i]);
}
stopMovingBackgound(flappy.layerName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flappy.stopFlapping() should be it.


}

function backgroundChange(layer){
desertHide()
gothamHide()
Expand Down Expand Up @@ -118,4 +128,4 @@ function gothamShow(){
function gothamHide(){
hide_layer('Gotham');
hide_layer('Gotham_obstacles');
}
}
21 changes: 15 additions & 6 deletions javascript/flapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ Flappy.prototype = {
velocity : 0,
gravity : 1.8,
flapVelocity : -20,

startFlapping : function() {
this.action.start();
this.position.show();
},
stopFlapping : function() {
this.action.stop();
},

fly : function() {
this.velocity += this.gravity;
this.position.y = this.position.y + this.velocity;
Expand Down Expand Up @@ -55,7 +55,7 @@ Flappy.prototype = {
return;

var c = isOverlap(flappy_rect, o_rect);

if (c || o_rect.right < flappy_rect.left)
obstacles.push(obstacles.shift());

Expand All @@ -69,7 +69,7 @@ Flappy.prototype = {

//On collision code here.
if (this._isCollided)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an isCollided method which you should use in favor of the attribute.

alert("hit");
onCollision();
},

get isCollided(){
Expand All @@ -81,7 +81,7 @@ var flappy = null;

function characterChange(layer) {
hide_layer('bird');
hide_layer('bat');
hide_layer('bat');
hide_layer('alien');
hide_layer('flappydino');
hide_layer('helicopter');
Expand Down Expand Up @@ -111,4 +111,13 @@ function stopFlappingBackgound(name) {
//Parameters are rects
function isOverlap(e1, e2) {
return (e1.top <= e2.bottom && e2.top <= e1.bottom && e1.right >= e2.left && e1.left <= e2.right);
}
}

function onCollision(){
show_layer('gameover');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! Now I know, what it is about.

stopAllBackgrounds();
}

function restartGame(){
location.reload();
}
2 changes: 2 additions & 0 deletions javascript/start.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Execute everything that should be started.
// This script must be the last script. Otherwise not all functions may be loaded.



window.onload = function() {
scaleToFullscreen();
showStartScreen();
Expand Down