change scoring and sorting
This commit is contained in:
parent
5414c719f1
commit
155257514d
4 changed files with 16 additions and 6 deletions
|
@ -51,9 +51,13 @@ class Player extends Entity {
|
||||||
player.ticks = 0;
|
player.ticks = 0;
|
||||||
}
|
}
|
||||||
handleTick(game) {
|
handleTick(game) {
|
||||||
|
|
||||||
let { entities, width, height } = game;
|
let { entities, width, height } = game;
|
||||||
|
|
||||||
let ent = this;
|
let ent = this;
|
||||||
|
ent.headCount += 1/200;
|
||||||
|
|
||||||
|
ent.headCount = Math.round(ent.headCount * 1000) / 1000;
|
||||||
|
|
||||||
if (ent.health <= 0) return;
|
if (ent.health <= 0) return;
|
||||||
|
|
||||||
|
@ -95,7 +99,7 @@ class Player extends Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target.type == 'Shooter') {
|
if (target.type == 'Shooter') {
|
||||||
this.health = 0;
|
this.health -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target.immortal) continue;
|
if (target.immortal) continue;
|
||||||
|
@ -113,7 +117,7 @@ class Player extends Entity {
|
||||||
console.log(`Player ${target.you} died to a player ${ent.you}`);
|
console.log(`Player ${target.you} died to a player ${ent.you}`);
|
||||||
ent.health -= dmg;
|
ent.health -= dmg;
|
||||||
if (ent.health > 100) ent.health = 100;
|
if (ent.health > 100) ent.health = 100;
|
||||||
ent.headCount++;
|
ent.headCount += 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
5
game.js
5
game.js
|
@ -49,7 +49,8 @@ class Game extends GameBasic {
|
||||||
|
|
||||||
if (!hash) {
|
if (!hash) {
|
||||||
hash = createHash('sha256');
|
hash = createHash('sha256');
|
||||||
hash.update(client.ip || '');
|
hash.update((+new Date) + '');
|
||||||
|
//hash.update(client.ip || '');
|
||||||
hash = hash.digest('hex');
|
hash = hash.digest('hex');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +109,7 @@ class Game extends GameBasic {
|
||||||
that.entities.push(new NPC(false, that))
|
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))
|
that.entities.push(new Shooter(false, that))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
index.js
5
index.js
|
@ -62,7 +62,12 @@ app.ws('/', function (ws, req) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
j = await j.json();
|
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;
|
ws.username = j.username;
|
||||||
|
|
||||||
console.log(`Player ${player.you} uses username ${ws.username}`)
|
console.log(`Player ${player.you} uses username ${ws.username}`)
|
||||||
})()
|
})()
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -100,7 +100,7 @@ class Game extends GameBasic {
|
||||||
ctx.textBaseline = "bottom";
|
ctx.textBaseline = "bottom";
|
||||||
ctx.font = "bold 16px sans-serif";
|
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.strokeText(...args);
|
||||||
ctx.fillText(...args);
|
ctx.fillText(...args);
|
||||||
|
@ -259,7 +259,7 @@ class Game extends GameBasic {
|
||||||
scores[e.ip] += e.ko ** 2;
|
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');
|
document.querySelector('.lb').textContent = scores.map(x => `${x[0]}: ${x[1]}`).join('\n');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue