From 8c43c89991f03028d2ca8d9398b410764c9ae14a Mon Sep 17 00:00:00 2001 From: Atsuyo-INSA Date: Wed, 6 Dec 2023 10:53:02 +0100 Subject: [PATCH] death --- js/class.js | 5 ----- js/game.js | 5 +++++ js/network.js | 4 ++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/js/class.js b/js/class.js index 5f1b4ab..971690d 100644 --- a/js/class.js +++ b/js/class.js @@ -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) diff --git a/js/game.js b/js/game.js index 9390237..a1eb732 100644 --- a/js/game.js +++ b/js/game.js @@ -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); } diff --git a/js/network.js b/js/network.js index 469715d..5160345 100644 --- a/js/network.js +++ b/js/network.js @@ -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",