mirror of
https://github.com/danbulant/bobek
synced 2026-06-16 04:41:11 +00:00
commit
6c2d5ff64b
1 changed files with 26 additions and 0 deletions
26
game.js
26
game.js
|
|
@ -1,6 +1,7 @@
|
|||
const RAD = Math.PI/180;
|
||||
const scrn = document.getElementById('canvas');
|
||||
const sctx = scrn.getContext("2d");
|
||||
scrn.tabIndex = 1;
|
||||
scrn.addEventListener("click",()=>{
|
||||
switch (state.curr) {
|
||||
case state.getReady :
|
||||
|
|
@ -21,6 +22,31 @@
|
|||
}
|
||||
})
|
||||
|
||||
scrn.onkeydown = function keyDown(e) {
|
||||
if (e.keyCode == 32 || e.keyCode == 87 || e.keyCode == 38) // Space Key or W key or arrow up
|
||||
{
|
||||
switch (state.curr) {
|
||||
case state.getReady :
|
||||
state.curr = state.Play;
|
||||
SFX.start.play();
|
||||
break;
|
||||
case state.Play :
|
||||
bird.flap();
|
||||
break;
|
||||
case state.gameOver :
|
||||
state.curr = state.getReady;
|
||||
bird.speed = 0;
|
||||
bird.y = 100;
|
||||
pipe.pipes=[];
|
||||
UI.score.curr = 0;
|
||||
SFX.played=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
let frames = 0;
|
||||
let dx = 2;
|
||||
const state = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue