change scoring and sorting

This commit is contained in:
biglyderv 2024-11-25 14:14:21 -05:00
parent 5414c719f1
commit 155257514d
4 changed files with 16 additions and 6 deletions

View file

@ -51,9 +51,13 @@ class Player extends Entity {
player.ticks = 0;
}
handleTick(game) {
let { entities, width, height } = game;
let ent = this;
ent.headCount += 1/200;
ent.headCount = Math.round(ent.headCount * 1000) / 1000;
if (ent.health <= 0) return;
@ -95,7 +99,7 @@ class Player extends Entity {
}
if (target.type == 'Shooter') {
this.health = 0;
this.health -= 1;
}
if (target.immortal) continue;
@ -113,7 +117,7 @@ class Player extends Entity {
console.log(`Player ${target.you} died to a player ${ent.you}`);
ent.health -= dmg;
if (ent.health > 100) ent.health = 100;
ent.headCount++;
ent.headCount += 100;
}
}
}

View file

@ -49,7 +49,8 @@ class Game extends GameBasic {
if (!hash) {
hash = createHash('sha256');
hash.update(client.ip || '');
hash.update((+new Date) + '');
//hash.update(client.ip || '');
hash = hash.digest('hex');
}
@ -108,7 +109,7 @@ class Game extends GameBasic {
that.entities.push(new NPC(false, that))
}
for (let i = 0; i < 30; i++) {
for (let i = 0; i < 18; i++) {
that.entities.push(new Shooter(false, that))
}

View file

@ -62,7 +62,12 @@ app.ws('/', function (ws, req) {
}
);
j = await j.json();
if (game.ws.findIndex(x => x.username == j.username) != -1) {
console.log(`Player ${player.you} uses username ${ws.username} illegally`)
return;
}
ws.username = j.username;
console.log(`Player ${player.you} uses username ${ws.username}`)
})()
return;

View file

@ -100,7 +100,7 @@ class Game extends GameBasic {
ctx.textBaseline = "bottom";
ctx.font = "bold 16px sans-serif";
let args = [`HP: ${ent.health} KO: ${ent.headCount} XY: ${Math.round(ent.pos.x)}, ${Math.round(ent.pos.y)}`, ent.pos.x, ent.pos.y - 64 / 2];
let args = [`HP: ${ent.health} PT: ${ent.headCount} XY: ${Math.round(ent.pos.x)}, ${Math.round(ent.pos.y)}`, ent.pos.x, ent.pos.y - 64 / 2];
ctx.strokeText(...args);
ctx.fillText(...args);
@ -259,7 +259,7 @@ class Game extends GameBasic {
scores[e.ip] += e.ko ** 2;
}
scores = Object.entries(scores).sort((a,b) => b.ko - a.ko);
scores = Object.entries(scores).sort((a,b) => b[1] - a[1]);
document.querySelector('.lb').textContent = scores.map(x => `${x[0]}: ${x[1]}`).join('\n');
}