IO of LeaderBoard
This commit is contained in:
parent
8be4120b36
commit
01213ac742
3 changed files with 32 additions and 1 deletions
|
@ -36,6 +36,7 @@ class Player
|
|||
this.health-=amount;
|
||||
if(this.health<=0)
|
||||
{
|
||||
this.death++;
|
||||
network.died(this.id,killerId);
|
||||
this.health=10;
|
||||
}
|
||||
|
|
20
js/game.js
20
js/game.js
|
@ -112,6 +112,25 @@ function updateBullets(dt)
|
|||
}
|
||||
}
|
||||
|
||||
function updateKills()
|
||||
{
|
||||
let deaths = Net.getDeathToAdd();
|
||||
deaths.forEach((object) => {
|
||||
let dead = object.id;
|
||||
let killer = object.killerId;
|
||||
console.log(killer,"killed",dead);
|
||||
if(player.id==killer)
|
||||
player.kill++;
|
||||
for(let i=0;i<players.length;i++)
|
||||
{
|
||||
if(players[i].id==dead)
|
||||
players[i].death++;
|
||||
if(players[i].id==killer)
|
||||
players[i].kill++;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let currentTime = new Date();
|
||||
function game() {
|
||||
if(playerId==null)
|
||||
|
@ -140,6 +159,7 @@ function game() {
|
|||
addPlayers();
|
||||
remPlayers();
|
||||
addBullets();
|
||||
updateKills();
|
||||
player.update(squares, circles, dt);
|
||||
for (var i = players.length - 1; i >= 0; i--) {
|
||||
players[i].update(squares, circles, dt);
|
||||
|
|
|
@ -9,6 +9,7 @@ class Network{
|
|||
this.playersToRemove = [];
|
||||
this.playersToUpdate = [];
|
||||
this.bulletsToAdd = [];
|
||||
this.deathToAdd = [];
|
||||
}
|
||||
|
||||
message(data){
|
||||
|
@ -38,7 +39,9 @@ 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("player",data.data.id,"died");
|
||||
console.log("player",data.data.id,"was killed by",data.data.killerId);
|
||||
this.deathToAdd.push(data.data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -93,4 +96,11 @@ class Network{
|
|||
this.playersToUpdate = [];
|
||||
return tmp;
|
||||
}
|
||||
|
||||
getDeathToAdd()
|
||||
{
|
||||
let tmp = this.deathToAdd;
|
||||
this.deathToAdd=[];
|
||||
return tmp;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue