correction

This commit is contained in:
Baptiste 2023-11-29 16:21:20 +01:00
parent 49cc48b33a
commit a181737dbb
2 changed files with 49 additions and 3 deletions

View file

@ -1,5 +1,4 @@
Renderer = new Render("canvas", "./assets/map/map7_recadr.png");
Inp = new Input("canvas");
let Net = new Network("ws://129.151.227.50:8080/", Renderer);
//let ClientKeyboard = new Keyboard()
@ -7,14 +6,14 @@ let Net = new Network("ws://129.151.227.50:8080/", Renderer);
let playerId; //id of client player
let players = [];
Inp = new Input("canvas");
Net.connect(); //connect to server, create a player, and retrieve all players info
//ClientKeyboard.init();
function game() {
for (var i = players.length - 1; i >= 0; i--) {
players[i].update([],[]);
}
//console.log(Inp.calculateAngle(500,500))

View file

@ -1,5 +1,8 @@
class Input {
constructor(id) {
this.keysDown = new Set()
this.dir = 0;
this.canvas = document.getElementById(id);
this.mouseX = 0
@ -28,6 +31,50 @@ class Input {
break;
}
});
window.addEventListener("keydown", (e)=>{
this.keysDown.add(e.key.toLowerCase())
this.updateDir();
})
window.addEventListener("keyup", (e)=>{
this.keysDown.delete(e.key.toLowerCase())
this.updateDir();
})
}
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;
}
}
get getDirection() {
return this.dir;
}
handleMouseMove(event) {