MULTIPLAYERgit add *

This commit is contained in:
Atsuyo-INSA 2023-11-29 18:36:28 +01:00
parent 2d43bb9288
commit cebdcd2942
3 changed files with 19 additions and 3 deletions

View file

@ -52,7 +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,"}");
//console.log("Should send: {type='update', dir=",this.dir,", x=",this.x,", y=",this.y,"}");
}
update(squares,circles)//update position

View file

@ -34,6 +34,22 @@ function game() {
}
else
{
let playerToUpdate = Net.getPlayersToUpdate();
for (let i = 0;i<playerToUpdate.length;i++)
{
for (let j = 0;j<players.length;j++)
{
if(players[j].id==playerToUpdate[i].id)
{
console.log("updated player",playerToUpdate[i].id);
players[j].x=playerToUpdate[i].x;
players[j].y=playerToUpdate[i].y;
players[j].dir=playerToUpdate[i].dir;
players[j].visibledir=playerToUpdate[i].visibledir;
break;
}
}
}
player.update([],[]);
for (var i = players.length - 1; i >= 0; i--) {
players[i].update([],[]);//squares, circles

View file

@ -79,8 +79,8 @@ class Input {
}
if(oldDir!=this.dir)
{
this.player.changeDirection(this.dir)
this.network.update(this.player)
this.player.changeDirection(this.dir);
this.network.update(this.player);
}
}