finally, now multiplayer
This commit is contained in:
parent
873102a927
commit
b1501d7251
6 changed files with 93 additions and 17 deletions
21
game.js
21
game.js
|
@ -3,19 +3,30 @@ import GameBasic from "./common/game_basic.js";
|
|||
class Game extends GameBasic {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
createPlayer(user) {
|
||||
|
||||
this.ws = [];
|
||||
}
|
||||
sync() {
|
||||
|
||||
let { entities } = this;
|
||||
let entList = [];
|
||||
for (let entity of entities) {
|
||||
let { pos, vel, rot, dir, health, headCount, you, camera } = entity;
|
||||
entList.push({ pos, vel, rot, dir, health, headCount, you, camera });
|
||||
}
|
||||
|
||||
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 / 10);
|
||||
setInterval(function () { that.sync() }, 1000 / 20);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue