Make players mobs too !

This commit is contained in:
2026-09-30 10:42:52 -03:00
parent 65f27d6099
commit 4fbcca6851
23 changed files with 314 additions and 132 deletions
+12
View File
@@ -4,6 +4,8 @@ import type { ClientLevel } from "../level/client_level.ts";
import { Player } from "./player.ts";
const SMOOTHING = 12;
// how long they flash red after being hurt, like minecraft
const HURT_TICKS = 10;
// another player on the server, it moves where the server says instead of simulating anything
export class RemotePlayer extends Player {
@@ -11,6 +13,8 @@ export class RemotePlayer extends Player {
target_x: number;
target_y: number;
target_z: number;
// counting down after a hurt event
hurt_time = 0;
constructor(level: ClientLevel, info: PlayerInfo) {
super(level, info.id, info.name);
@@ -33,7 +37,15 @@ export class RemotePlayer extends Player {
this.pitch = pitch;
}
// players respawn straight away, so dying doesn't show
on_event(event: "hurt" | "death") {
if (event === "hurt") {
this.hurt_time = HURT_TICKS;
}
}
tick() {
if (this.hurt_time > 0) this.hurt_time -= 1;
const t = Math.min(1, TICK_DELTA * SMOOTHING);
this.x += (this.target_x - this.x) * t;
this.y += (this.target_y - this.y) * t;