This commit is contained in:
Atsuyo-INSA 2023-12-06 10:53:02 +01:00
parent 25a350e1e5
commit 8c43c89991
3 changed files with 9 additions and 5 deletions

View file

@ -29,11 +29,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

@ -131,6 +131,11 @@ function game() {
remPlayers();
addBullets();
player.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);
}

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",