del: keyboard

This commit is contained in:
Baptiste 2023-11-29 17:38:23 +01:00
parent d194440762
commit 5d1a672094

View file

@ -1,66 +0,0 @@
/////////////
/////////////
/////////////
// DEAD CLASS !!!
// DO NOT USE
class Keyboard{
constructor(){
this.keysDown = new Set()
this.dir = 0;
}
updateDir(){
if(this.keysDown.has('z')){
if(this.keysDown.has('d')){
this.dir = 2;
}else if(this.keysDown.has('s')){
this.dir = 0;
}else if(this.keysDown.has('q')){
this.dir = 8;
}else{
this.dir = 1;
}
}else if(this.keysDown.has('d')){
if(this.keysDown.has('s')){
this.dir = 4;
}else if(this.keysDown.has('q')){
this.dir = 0;
}else{
this.dir = 3;
}
}else if(this.keysDown.has('s')){
if(this.keysDown.has('q')){
this.dir = 6;
}else{
this.dir = 5;
}
}else if(this.keysDown.has('q')){
this.dir = 7;
}
}
getDirection(){
return this.dir;
}
init(){
document.addEventListener("keydown", (e)=>{
this.keysDown.add(e.key.toLowerCase())
this.updateDir();
})
document.addEventListener("keyup", (e)=>{
this.keysDown.delete(e.key.toLowerCase())
this.updateDir();
})
}
}