2024-09-29 03:16:15 -04:00
|
|
|
import GameBasic from "./common/game_basic.js";
|
2024-10-01 04:03:55 -04:00
|
|
|
import NPC from "./common/npc.js";
|
2024-09-29 03:16:15 -04:00
|
|
|
|
|
|
|
class Game extends GameBasic {
|
|
|
|
constructor() {
|
|
|
|
super();
|
2024-09-29 03:55:22 -04:00
|
|
|
this.ws = [];
|
2024-09-29 03:16:15 -04:00
|
|
|
}
|
|
|
|
sync() {
|
2024-09-29 03:55:22 -04:00
|
|
|
let { entities } = this;
|
|
|
|
let entList = [];
|
|
|
|
for (let entity of entities) {
|
2024-10-01 04:03:55 -04:00
|
|
|
let { pos, vel, rot, dir, health, headCount, you, camera, ticks, type, isMenu, r, playing } = entity;
|
|
|
|
entList.push({ pos, vel, rot, dir, health, headCount, you, camera, ticks, type, isMenu, r, playing });
|
2024-09-29 03:55:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (entList.length == 0) return;
|
|
|
|
|
|
|
|
for (let client of this.ws) {
|
|
|
|
if (!client.active) continue;
|
|
|
|
client.send(JSON.stringify(entList));
|
|
|
|
}
|
2024-10-01 04:03:55 -04:00
|
|
|
|
|
|
|
for (let entity of entities) {
|
|
|
|
entity.r = 1;
|
|
|
|
}
|
2024-09-29 03:16:15 -04:00
|
|
|
}
|
|
|
|
init() {
|
|
|
|
super.init();
|
|
|
|
|
|
|
|
let that = this;
|
2024-09-29 03:55:22 -04:00
|
|
|
that.entities = [];
|
2024-09-29 03:16:15 -04:00
|
|
|
|
2024-10-01 04:03:55 -04:00
|
|
|
for (let i = 0; i < 10; i++) {
|
|
|
|
that.entities.push(new NPC())
|
|
|
|
}
|
|
|
|
|
2024-09-29 17:07:22 -04:00
|
|
|
setInterval(function () { that.sync() }, 1000 / 5);
|
2024-09-29 03:16:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Game;
|