From 9ea6330fe366ac7beb2d073621cfc0fa06cf3667 Mon Sep 17 00:00:00 2001 From: Killian Marty Date: Wed, 6 Dec 2023 10:49:18 +0100 Subject: [PATCH 1/3] srv --- server/server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/server.js b/server/server.js index 292ef67..cf69b3b 100644 --- a/server/server.js +++ b/server/server.js @@ -122,7 +122,7 @@ wss.on('connection', (socket, req) => { broadcast(JSON.stringify(message), socket.id); } else if(message.type=="died"){ - + console.log(message) broadcast(JSON.stringify(message), socket.id); for (var i = players.length - 1; i >= 0; i--) { From 25a350e1e5b2f05b18a014ae44e3e4356be50b8b Mon Sep 17 00:00:00 2001 From: Killian Marty Date: Wed, 6 Dec 2023 10:51:39 +0100 Subject: [PATCH 2/3] srv --- server/server.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/server.js b/server/server.js index cf69b3b..2e047b0 100644 --- a/server/server.js +++ b/server/server.js @@ -122,7 +122,6 @@ wss.on('connection', (socket, req) => { broadcast(JSON.stringify(message), socket.id); } else if(message.type=="died"){ - console.log(message) broadcast(JSON.stringify(message), socket.id); for (var i = players.length - 1; i >= 0; i--) { From 8c43c89991f03028d2ca8d9398b410764c9ae14a Mon Sep 17 00:00:00 2001 From: Atsuyo-INSA Date: Wed, 6 Dec 2023 10:53:02 +0100 Subject: [PATCH 3/3] 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",