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) takeDamage(amount)
{ {
this.health-=amount; this.health-=amount;
if(this.health<=0)
{
//send death message to server
//this.reset()
}
} }
retrieveServerInfo(id,x,y,dir) retrieveServerInfo(id,x,y,dir)

View file

@ -133,10 +133,14 @@ function game() {
remPlayers(); remPlayers();
addBullets(); addBullets();
player.update(squares, circles, dt); player.update(squares, circles, dt);
if(player.health <= 0)
players.forEach((p) => { {
p.update(squares, circles, dt); Net.died(player.id);
}); player.health=10;
}
for (var i = players.length - 1; i >= 0; i--) {
players[i].update(squares, circles, dt);
}
Renderer.ReloadAff(); Renderer.ReloadAff();
updateBullets(dt); updateBullets(dt);
LB.ReloadAff(players, player); 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 update(obj){ //send data to server in order to broadcast
this.socket.send(JSON.stringify({ this.socket.send(JSON.stringify({
type: "update", type: "update",

View file

@ -122,7 +122,6 @@ wss.on('connection', (socket, req) => {
broadcast(JSON.stringify(message), socket.id); broadcast(JSON.stringify(message), socket.id);
} else if(message.type=="died"){ } else if(message.type=="died"){
broadcast(JSON.stringify(message), socket.id); broadcast(JSON.stringify(message), socket.id);
for (var i = players.length - 1; i >= 0; i--) { for (var i = players.length - 1; i >= 0; i--) {