This commit is contained in:
Killian Marty 2023-12-06 10:42:53 +01:00
parent 86d3bb86d8
commit 49e9add522

View file

@ -105,17 +105,38 @@ wss.on('connection', (socket, req) => {
socket.on('message', (message) => {
message = JSON.parse(message);
if (message.type == "ping") {
socket.send("pong");
}else if(message.type=="update") {
for (var i = players.length - 1; i >= 0; i--) {
if(players[i].id == message.data.id){
players[i]=message.data;
}
}
broadcast(JSON.stringify(message), socket.id);
} else if(message.type=="newBullet"){
console.log(message);
broadcast(JSON.stringify(message), socket.id);
} else if(message.type=="died"){
broadcast(JSON.stringify(message), socket.id);
for (var i = players.length - 1; i >= 0; i--) {
if(players[i].id == message.data.id){
let pos = generatePosition();
players[i].x=pos[0];
players[i].y=pos[1];
broadcast(JSON.stringify({
type:"update",
data: players[i]
}))
}
}
}
});