Only auto aim and healthbars

This commit is contained in:
armel committed 2026-09-07 23:02:47 +02:00
1 parent 54c6327ac7
commit a914bd74fe
14 files changed
+95 -89

No files matched your search

+24
View File
@@ -93,6 +93,9 @@ export class NetEntities {
this._stampPlayer(view, snapshot, now);
if (!snapshot.dead) {
view.draw(renderer);
if (snapshot.name) {
this._drawName(snapshot, renderer, textRenderer);
}
}
}
@@ -110,6 +113,27 @@ export class NetEntities {
this.players.clear();
}
_drawName(snapshot, renderer, textRenderer) {
const hp = snapshot.hp ?? 0;
const mhp = snapshot.mhp ?? hp;
const label = `${snapshot.name} HP: ${hp}/${mhp}`;
const opts = { size: 12, fillStyle: '#fff', bold: true };
const entry = textRenderer.measure(label, opts);
const barW = 40;
const barH = 4;
const barX = snapshot.x - barW / 2;
const barY = snapshot.y - PLAYER_SIZE / 2 - barH - 2;
renderer.drawTexture(renderer.whiteTexture, barX, barY, barW, barH, [0, 0, 0, 0.6]);
const ratio = mhp > 0 ? Math.max(0, Math.min(1, hp / mhp)) : 0;
if (ratio > 0) {
const color = ratio > 2 / 3 ? [0.3, 0.9, 0.35, 0.9] : ratio > 1 / 3 ? [0.95, 0.8, 0.2, 0.9] : [0.9, 0.25, 0.25, 0.9];
renderer.drawTexture(renderer.whiteTexture, barX, barY, barW * ratio, barH, color);
}
textRenderer.draw(renderer, label, snapshot.x - entry.width / 2, barY - entry.height - 2, opts);
}
_stamp(view, entity, now) {
view.pos.x = entity.x;
view.pos.y = entity.y;
+1 -2
View File
@@ -140,13 +140,12 @@ export class NetworkClient {
_flushInput() {
if (!this._input || !this._connected()) return;
const { id, keys, aim, fire, autoAim } = this._input;
const { id, keys, aim, fire } = this._input;
this.socket.trigger('client-input', this._inputChannel(), {
id,
keys,
aim,
fire,
autoAim,
});
}