unibutton/game.js

33 lines
811 B
JavaScript
Raw Normal View History

2024-09-29 03:16:15 -04:00
import GameBasic from "./common/game_basic.js";
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-09-29 22:37:33 -04:00
let { pos, vel, rot, dir, health, headCount, you, camera, ticks } = entity;
entList.push({ pos, vel, rot, dir, health, headCount, you, camera, ticks });
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-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-09-29 17:07:22 -04:00
setInterval(function () { that.sync() }, 1000 / 5);
2024-09-29 03:16:15 -04:00
}
}
export default Game;