unibutton/game.js
2024-09-29 22:37:33 -04:00

33 lines
No EOL
811 B
JavaScript

import GameBasic from "./common/game_basic.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 } = entity;
entList.push({ pos, vel, rot, dir, health, headCount, you, camera, ticks });
}
if (entList.length == 0) return;
for (let client of this.ws) {
if (!client.active) continue;
client.send(JSON.stringify(entList));
}
}
init() {
super.init();
let that = this;
that.entities = [];
setInterval(function () { that.sync() }, 1000 / 5);
}
}
export default Game;