-
Notifications
You must be signed in to change notification settings - Fork 157
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
Changes from 3 commits
1296d68
fc57edc
5de5d2d
f5a54ef
b3c8287
eb70a93
a9e3add
2c22a0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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()); | ||
|
||
|
@@ -69,7 +69,7 @@ Flappy.prototype = { | |
|
||
//On collision code here. | ||
if (this._isCollided) | ||
alert("hit"); | ||
onCollision(); | ||
}, | ||
|
||
get isCollided(){ | ||
|
@@ -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'); | ||
|
@@ -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(){ | ||
document.getElementById('layer17').style.display="inline"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please do not use the id. Use the name. it is more descriptive and does not change when editing with Inkscape. You can use these functions: |
||
stopAllBackgrounds(); | ||
} | ||
|
||
function restartGame(){ | ||
location.reload(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
// Execute everything that should be started. | ||
// This script must be the last script. Otherwise not all functions may be loaded. | ||
|
||
var characters = ["bird", "bat", "alien","flappydino","helicopter"]; | ||
var backgrounds=["background","Gotham"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
var path_obstacles=["cactus","Gotham_obstacles"]; | ||
var skyobjects=["DayAndNight","SunAndMoon"]; | ||
|
||
|
||
window.onload = function() { | ||
scaleToFullscreen(); | ||
showStartScreen(); | ||
|
||
var characters = ["bird", "bat", "alien","flappydino","helicopter"]; | ||
var backgrounds=["background","Gotham"]; | ||
|
||
|
||
rand=Math.floor((Math.random() * (backgrounds.length))); | ||
backgroundChange(backgrounds[rand]) | ||
|
There was a problem hiding this comment.
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.