mirror of
https://github.com/danbulant/bobek
synced 2026-06-24 17:11:57 +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 RAD = Math.PI/180;
|
||||||
const scrn = document.getElementById('canvas');
|
const scrn = document.getElementById('canvas');
|
||||||
const sctx = scrn.getContext("2d");
|
const sctx = scrn.getContext("2d");
|
||||||
|
scrn.tabIndex = 1;
|
||||||
scrn.addEventListener("click",()=>{
|
scrn.addEventListener("click",()=>{
|
||||||
switch (state.curr) {
|
switch (state.curr) {
|
||||||
case state.getReady :
|
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 frames = 0;
|
||||||
let dx = 2;
|
let dx = 2;
|
||||||
const state = {
|
const state = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue