This commit is contained in:
Baptiste 2023-12-06 14:03:22 +01:00
commit 7b7da9b4eb
4 changed files with 12 additions and 10 deletions

View file

@ -32,11 +32,6 @@ class Player
takeDamage(amount)
{
this.health-=amount;
if(this.health<=0)
{
//send death message to server
//this.reset()
}
}
retrieveServerInfo(id,x,y,dir)

View file

@ -133,10 +133,14 @@ function game() {
remPlayers();
addBullets();
player.update(squares, circles, dt);
players.forEach((p) => {
p.update(squares, circles, dt);
});
if(player.health <= 0)
{
Net.died(player.id);
player.health=10;
}
for (var i = players.length - 1; i >= 0; i--) {
players[i].update(squares, circles, dt);
}
Renderer.ReloadAff();
updateBullets(dt);
LB.ReloadAff(players, player);

View file

@ -52,6 +52,10 @@ class Network{
})
}
die(id_){
this.socket.send(JSON.stringify({type:"died",data:{id:id_}}));
}
update(obj){ //send data to server in order to broadcast
this.socket.send(JSON.stringify({
type: "update",

View file

@ -122,7 +122,6 @@ wss.on('connection', (socket, req) => {
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--) {