starting keyboard interaction
This commit is contained in:
parent
2440fa114b
commit
7f60fc5d71
4 changed files with 9 additions and 4 deletions
|
@ -52,6 +52,7 @@ class Player
|
|||
if(this.dir!=0){
|
||||
this.visibleDir = newDirection;
|
||||
}
|
||||
console.log("Should send: {type='update', dir=",this.dir,", x=",this.x,", y=",this.y,"}");
|
||||
}
|
||||
|
||||
update(squares,circles)//update position
|
||||
|
|
|
@ -29,6 +29,7 @@ function game() {
|
|||
}
|
||||
else
|
||||
{
|
||||
player.update([],[]);
|
||||
for (var i = players.length - 1; i >= 0; i--) {
|
||||
players[i].update([],[]);//squares, circles
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ class Input {
|
|||
constructor(id) {
|
||||
this.keysDown = new Set()
|
||||
this.dir = 0;
|
||||
|
||||
this.player=null;
|
||||
this.canvas = document.getElementById(id);
|
||||
|
||||
this.mouseX = 0
|
||||
|
@ -15,7 +15,7 @@ class Input {
|
|||
console.log("Clic de la souris");
|
||||
});
|
||||
|
||||
window.addEventListener("keydown", function(event) {
|
||||
/*window.addEventListener("keydown", function(event) {
|
||||
switch(event.key) {
|
||||
case "ArrowUp":
|
||||
console.log("Flèche du haut");
|
||||
|
@ -30,7 +30,7 @@ class Input {
|
|||
console.log("Flèche de droite pressée");
|
||||
break;
|
||||
}
|
||||
});
|
||||
});*/
|
||||
|
||||
window.addEventListener("keydown", (e)=>{
|
||||
this.keysDown.add(e.key.toLowerCase())
|
||||
|
@ -44,6 +44,8 @@ class Input {
|
|||
}
|
||||
|
||||
updateDir(){
|
||||
if(this.player==null)
|
||||
return;
|
||||
if(this.keysDown.has('z')){
|
||||
if(this.keysDown.has('d')){
|
||||
this.dir = 2;
|
||||
|
@ -71,6 +73,7 @@ class Input {
|
|||
}else if(this.keysDown.has('q')){
|
||||
this.dir = 7;
|
||||
}
|
||||
this.player.updateDir(this.dir)
|
||||
}
|
||||
|
||||
get getDirection() {
|
||||
|
|
|
@ -16,7 +16,7 @@ class Network{
|
|||
this.playerId = data.data.playerId;
|
||||
for (var i = data.data.players.length - 1; i >= 0; i--) {
|
||||
if(data.data.players[i].id==this.playerId)
|
||||
this.clientPlayer=data.data.players[i];
|
||||
this.clientPlayer=new Player(data.data.players[i].id, data.data.players[i].x, data.data.players[i].y, data.data.players[i].name, data.data.players[i].dir);
|
||||
else
|
||||
this.playersToAdd.push(new Player(data.data.players[i].id, data.data.players[i].x, data.data.players[i].y, data.data.players[i].name, data.data.players[i].dir))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue