import GameBasic from "./common/game_basic.js"; import NPC from "./common/npc.js"; class Game extends GameBasic { constructor() { super(); this.ws = []; } sync() { let { entities } = this; let entList = []; for (let entity of entities) { 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 }); } if (entList.length == 0) return; for (let client of this.ws) { if (!client.active) continue; client.send(JSON.stringify(entList)); } for (let entity of entities) { entity.r = 1; } } init() { super.init(); let that = this; that.entities = []; for (let i = 0; i < 10; i++) { that.entities.push(new NPC()) } setInterval(function () { that.sync() }, 1000 / 5); } } export default Game;