mirror of
https://github.com/danbulant/bobek
synced 2026-07-05 02:50:38 +00:00
pipes w/ no functionality
This commit is contained in:
parent
dbb6ff2aa8
commit
54e73b692a
1 changed files with 37 additions and 5 deletions
42
game.js
42
game.js
|
|
@ -1,5 +1,4 @@
|
||||||
const RAD = Math.PI/180;
|
const RAD = Math.PI/180;
|
||||||
const dx = 2;
|
|
||||||
const scrn = document.getElementById('canvas');
|
const scrn = document.getElementById('canvas');
|
||||||
const sctx = scrn.getContext("2d");
|
const sctx = scrn.getContext("2d");
|
||||||
scrn.addEventListener("click",()=>{
|
scrn.addEventListener("click",()=>{
|
||||||
|
|
@ -12,11 +11,14 @@
|
||||||
break;
|
break;
|
||||||
case state.gameOver :
|
case state.gameOver :
|
||||||
state.curr = state.getReady;
|
state.curr = state.getReady;
|
||||||
|
bird.y = 100;
|
||||||
|
pipe.pipes=[];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
sctx.fillStyle = "#30c0df";
|
sctx.fillStyle = "#30c0df";
|
||||||
let frames = 0;
|
let frames = 0;
|
||||||
|
let dx = 2;
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
curr : 0,
|
curr : 0,
|
||||||
|
|
@ -37,7 +39,7 @@
|
||||||
|
|
||||||
switch (state.curr) {
|
switch (state.curr) {
|
||||||
case state.getReady :
|
case state.getReady :
|
||||||
this.x -= dx/2;
|
this.x -= 1;
|
||||||
break;
|
break;
|
||||||
case state.Play :
|
case state.Play :
|
||||||
this.x -= dx
|
this.x -= dx
|
||||||
|
|
@ -58,6 +60,33 @@
|
||||||
sctx.drawImage(this.sprite,this.x,y);
|
sctx.drawImage(this.sprite,this.x,y);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const pipe = {
|
||||||
|
top : {sprite : new Image()},
|
||||||
|
bot : {sprite : new Image()},
|
||||||
|
gap:85,
|
||||||
|
pipes : [],
|
||||||
|
draw : function(){
|
||||||
|
for(let i = 0;i<this.pipes.length;i++)
|
||||||
|
{
|
||||||
|
let p = this.pipes[i];
|
||||||
|
sctx.drawImage(this.top.sprite,p.x,p.y)
|
||||||
|
sctx.drawImage(this.bot.sprite,p.x,p.y+parseFloat(this.top.sprite.height)+this.gap)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
update : function(){
|
||||||
|
if(state.curr!=state.Play) return;
|
||||||
|
if(frames%100==0)
|
||||||
|
{
|
||||||
|
console.log("lol");
|
||||||
|
this.pipes.push({x:parseFloat(scrn.width),y:-210*Math.min(Math.random()+1,1.8)});
|
||||||
|
}
|
||||||
|
this.pipes.forEach(pipe=>{
|
||||||
|
pipe.x -= dx;
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
const bird = {
|
const bird = {
|
||||||
animations :
|
animations :
|
||||||
[
|
[
|
||||||
|
|
@ -83,12 +112,10 @@
|
||||||
sctx.restore();
|
sctx.restore();
|
||||||
},
|
},
|
||||||
update : function() {
|
update : function() {
|
||||||
console.log(this.speed ,this.rotatation);
|
|
||||||
switch (state.curr) {
|
switch (state.curr) {
|
||||||
case state.getReady :
|
case state.getReady :
|
||||||
bird.y = 100;
|
|
||||||
this.rotatation = 0;
|
this.rotatation = 0;
|
||||||
this.y += (frames%10==0) ? (Math.random()-0.5)*2 : 0;
|
this.y +=(frames%10==0) ? Math.sin(frames*RAD) :0;
|
||||||
this.frame += (frames%10==0) ? 1 : 0;
|
this.frame += (frames%10==0) ? 1 : 0;
|
||||||
break;
|
break;
|
||||||
case state.Play :
|
case state.Play :
|
||||||
|
|
@ -144,6 +171,8 @@
|
||||||
|
|
||||||
gnd.sprite.src="img/ground.png";
|
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.bot.sprite.src="img/botpipe.png";
|
||||||
UI.getReady.sprite.src="img/getready.png";
|
UI.getReady.sprite.src="img/getready.png";
|
||||||
UI.gameOver.sprite.src="img/gameOver.png";
|
UI.gameOver.sprite.src="img/gameOver.png";
|
||||||
bird.animations[0].sprite.src="img/bird/b0.png";
|
bird.animations[0].sprite.src="img/bird/b0.png";
|
||||||
|
|
@ -166,11 +195,14 @@ gameLoop();
|
||||||
{
|
{
|
||||||
bird.update();
|
bird.update();
|
||||||
gnd.update();
|
gnd.update();
|
||||||
|
pipe.update();
|
||||||
|
|
||||||
}
|
}
|
||||||
function draw()
|
function draw()
|
||||||
{
|
{
|
||||||
sctx.fillRect(0,0,scrn.width,scrn.height)
|
sctx.fillRect(0,0,scrn.width,scrn.height)
|
||||||
bg.draw();
|
bg.draw();
|
||||||
|
pipe.draw();
|
||||||
gnd.draw();
|
gnd.draw();
|
||||||
bird.draw();
|
bird.draw();
|
||||||
if(state.curr != state.Play)
|
if(state.curr != state.Play)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue