mirror of
https://github.com/danbulant/bobek
synced 2026-07-06 03:20:53 +00:00
merge
This commit is contained in:
commit
2f09c176e8
7 changed files with 52 additions and 25 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
# JS-Flappy-Bird
|
# JS-Flappy-Bird
|
||||||
Remake of the Original FlappyBird Using **JS** & **HTML Canvas**
|
Remake of the Original FlappyBird Using **JS** & **HTML Canvas**
|
||||||
|
# [Play it.](https://d4rk1n.github.io/JS-Flappy-Bird/index.html)
|
||||||
# Demo
|
# Demo
|
||||||

|

|
||||||
|
|
|
||||||
74
game.js
74
game.js
|
|
@ -236,50 +236,73 @@
|
||||||
const UI = {
|
const UI = {
|
||||||
getReady : {sprite : new Image()},
|
getReady : {sprite : new Image()},
|
||||||
gameOver : {sprite : new Image()},
|
gameOver : {sprite : new Image()},
|
||||||
|
tap : [{sprite : new Image()},
|
||||||
|
{sprite : new Image()}],
|
||||||
score : {
|
score : {
|
||||||
curr : 0,
|
curr : 0,
|
||||||
best : 0,
|
best : 0,
|
||||||
},
|
},
|
||||||
|
x :0,
|
||||||
|
y :0,
|
||||||
|
tx :0,
|
||||||
|
ty :0,
|
||||||
|
frame : 0,
|
||||||
draw : function() {
|
draw : function() {
|
||||||
switch (state.curr) {
|
switch (state.curr) {
|
||||||
case state.getReady :
|
case state.getReady :
|
||||||
curr = this.getReady;
|
this.y = parseFloat(scrn.height-this.getReady.sprite.height)/2;
|
||||||
|
this.x = parseFloat(scrn.width-this.getReady.sprite.width)/2;
|
||||||
|
this.tx = parseFloat(scrn.width - this.tap[0].sprite.width)/2;
|
||||||
|
this.ty = this.y + this.getReady.sprite.height- this.tap[0].sprite.height;
|
||||||
|
sctx.drawImage(this.getReady.sprite,this.x,this.y);
|
||||||
|
sctx.drawImage(this.tap[this.frame].sprite,this.tx,this.ty)
|
||||||
break;
|
break;
|
||||||
case state.gameOver :
|
case state.gameOver :
|
||||||
curr = this.gameOver;
|
this.y = parseFloat(scrn.height-this.gameOver.sprite.height)/2;
|
||||||
|
this.x = parseFloat(scrn.width-this.gameOver.sprite.width)/2;
|
||||||
|
this.tx = parseFloat(scrn.width - this.tap[0].sprite.width)/2;
|
||||||
|
this.ty = this.y + this.gameOver.sprite.height- this.tap[0].sprite.height;
|
||||||
|
sctx.drawImage(this.gameOver.sprite,this.x,this.y);
|
||||||
|
sctx.drawImage(this.tap[this.frame].sprite,this.tx,this.ty)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
y = parseFloat(scrn.height-curr.sprite.height)/2;
|
|
||||||
x = parseFloat(scrn.width-curr.sprite.width)/2;
|
|
||||||
if(state.curr!=state.Play)sctx.drawImage(curr.sprite,x,y);
|
|
||||||
this.drawScore();
|
this.drawScore();
|
||||||
},
|
},
|
||||||
drawScore : function() {
|
drawScore : function() {
|
||||||
sctx.fillStyle = "#FFFFFF";
|
sctx.fillStyle = "#FFFFFF";
|
||||||
sctx.strokeStyle = "#000000";
|
sctx.strokeStyle = "#000000";
|
||||||
if(state.curr == state.Play )
|
switch (state.curr) {
|
||||||
{
|
case state.Play :
|
||||||
sctx.lineWidth = "2";
|
sctx.lineWidth = "2";
|
||||||
sctx.font = "35px Squada One";
|
sctx.font = "35px Squada One";
|
||||||
sctx.fillText(this.score.curr,scrn.width/2,50);
|
sctx.fillText(this.score.curr,scrn.width/2-5,50);
|
||||||
sctx.strokeText(this.score.curr,scrn.width/2,50);
|
sctx.strokeText(this.score.curr,scrn.width/2-5,50);
|
||||||
}
|
break;
|
||||||
if(state.curr == state.gameOver )
|
case state.gameOver :
|
||||||
{
|
|
||||||
|
|
||||||
//this.score.best = Math.max(this.score.curr,localStorage.getItem("best"));
|
|
||||||
//localStorage.setItem("best",this.score.best);
|
|
||||||
sctx.lineWidth = "2";
|
sctx.lineWidth = "2";
|
||||||
sctx.font = "40px Squada One";
|
sctx.font = "40px Squada One";
|
||||||
let sc = `SCORE : ${this.score.curr}`
|
let sc = `SCORE : ${this.score.curr}`;
|
||||||
let bs = `BEST : ${this.score.best}`
|
try {
|
||||||
sctx.fillText(sc,scrn.width/2-80,scrn.height/2);
|
this.score.best = Math.max(this.score.curr,localStorage.getItem("best"));
|
||||||
sctx.strokeText(sc,scrn.width/2-80,scrn.height/2);
|
localStorage.setItem("best",this.score.best);
|
||||||
sctx.fillText(bs,scrn.width/2-80,scrn.height/2+30);
|
let bs = `BEST : ${this.score.best}`;
|
||||||
sctx.strokeText(bs,scrn.width/2-80,scrn.height/2+30);
|
sctx.fillText(sc,scrn.width/2-80,scrn.height/2+0);
|
||||||
|
sctx.strokeText(sc,scrn.width/2-80,scrn.height/2+0);
|
||||||
|
sctx.fillText(bs,scrn.width/2-80,scrn.height/2+30);
|
||||||
|
sctx.strokeText(bs,scrn.width/2-80,scrn.height/2+30);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
sctx.fillText(sc,scrn.width/2-85,scrn.height/2+15);
|
||||||
|
sctx.strokeText(sc,scrn.width/2-85,scrn.height/2+15);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
update : function() {
|
||||||
|
if(state.curr == state.Play) return;
|
||||||
|
this.frame += (frames % 10==0) ? 1 :0;
|
||||||
|
this.frame = this.frame % this.tap.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -288,8 +311,10 @@ gnd.sprite.src="img/ground.png";
|
||||||
bg.sprite.src="img/BG.png";
|
bg.sprite.src="img/BG.png";
|
||||||
pipe.top.sprite.src="img/toppipe.png";
|
pipe.top.sprite.src="img/toppipe.png";
|
||||||
pipe.bot.sprite.src="img/botpipe.png";
|
pipe.bot.sprite.src="img/botpipe.png";
|
||||||
|
UI.gameOver.sprite.src="img/go.png";
|
||||||
UI.getReady.sprite.src="img/getready.png";
|
UI.getReady.sprite.src="img/getready.png";
|
||||||
UI.gameOver.sprite.src="img/gameOver.png";
|
UI.tap[0].sprite.src="img/tap/t0.png";
|
||||||
|
UI.tap[1].sprite.src="img/tap/t1.png";
|
||||||
bird.animations[0].sprite.src="img/bird/b0.png";
|
bird.animations[0].sprite.src="img/bird/b0.png";
|
||||||
bird.animations[1].sprite.src="img/bird/b1.png";
|
bird.animations[1].sprite.src="img/bird/b1.png";
|
||||||
bird.animations[2].sprite.src="img/bird/b2.png";
|
bird.animations[2].sprite.src="img/bird/b2.png";
|
||||||
|
|
@ -315,6 +340,7 @@ gameLoop();
|
||||||
bird.update();
|
bird.update();
|
||||||
gnd.update();
|
gnd.update();
|
||||||
pipe.update();
|
pipe.update();
|
||||||
|
UI.update();
|
||||||
}
|
}
|
||||||
function draw()
|
function draw()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
BIN
img/gameover.png
BIN
img/gameover.png
Binary file not shown.
|
Before Width: | Height: | Size: 7.5 KiB |
BIN
img/getready.png
BIN
img/getready.png
Binary file not shown.
|
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 5.3 KiB |
BIN
img/go.png
Normal file
BIN
img/go.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 634 B |
BIN
img/tap/t0.png
Normal file
BIN
img/tap/t0.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1 KiB |
BIN
img/tap/t1.png
Normal file
BIN
img/tap/t1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Loading…
Reference in a new issue