Merge pull request #1 from fuboki10/master

Add key up / w / space
This commit is contained in:
Abdelrahman Arafat 2019-10-28 00:24:44 +02:00 committed by GitHub
commit 6c2d5ff64b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

26
game.js
View file

@ -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 = {