diff --git a/js/class.js b/js/class.js index 1449765..01d5a91 100644 --- a/js/class.js +++ b/js/class.js @@ -9,7 +9,7 @@ const defaulthealth=10.; class Player { - constructor (id,x,y,name, dir) + constructor (id,x,y,name, dir,net) { this.name=name; this.x=x; @@ -31,12 +31,18 @@ class Player this.death=0; } - takeDamage(amount) + takeDamage(amount,killerId,network) { this.health-=amount; + if(this.health<=0) + { + console.log(network); + network.died(this.id,killerId); + this.health=10; + } } - retrieveServerInfo(id,x,y,dir) + /*retrieveServerInfo(id,x,y,dir) { if(this.id==id) { @@ -46,7 +52,7 @@ class Player if(dir!=0) this.visibleDir=dir; } - } + }*/ changeDirection(newDirection){ this.dir = newDirection; @@ -124,13 +130,13 @@ class Bullet } } - checkCollisions(player,squares,circles)//only the client's player /!\ + checkCollisions(player,squares,circles,network)//only the client's player /!\ { if(!this.deleted) { if(player!=null && player.id!=this.parentId && Math.sqrt((player.x-this.x)**2+(player.y-this.y)**2)=0;i--) { bullets[i].update(dt); - bullets[i].checkCollisions(player,squares,circles); + bullets[i].checkCollisions(player,squares,circles,Net); if(bullets[i].deleted) { Renderer.remBullet(bullets[i]); @@ -137,11 +136,6 @@ 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 dee878b..758b78a 100644 --- a/js/network.js +++ b/js/network.js @@ -38,8 +38,7 @@ class Network{ this.bulletsToAdd.push(new Bullet(data.data.x,data.data.y,data.data.dx,data.data.dy,data.data.id)); break; case "died": - console.log(data.data); - console.log("someone died"); + console.log("player ",data.data.id," died"); default: break; }