add basic updating to client on physics

This commit is contained in:
Asraelite 2016-03-21 23:45:27 +00:00
parent 95e0f6b710
commit 1027d980c1
15 changed files with 160 additions and 13 deletions

View file

@ -9,9 +9,12 @@ class Room {
this.teamB = new Set();
this.world = new World();
this.name = (Math.random() * 100000 | 0).toString(36);
this.start();
}
add(player) {
console.log(`${player.name} joined ${this.name}.`);
player.room = this;
player.connection.room = this.name;
this.players.add(player);
@ -19,6 +22,14 @@ class Room {
this.world.addPlayer(player);
}
remove(player) {
console.log(`${player.name} left ${this.name}.`);
this.players.delete(player);
this.teamA.delete(player);
this.teamB.delete(player);
this.world.removePlayer(player);
}
setTeam(player, team) {
this.teamA.delete(player);
this.teamB.delete(player);
@ -26,6 +37,20 @@ class Room {
player.team = team;
}
update(self) {
self.players.forEach(player => player.sendUpdate());
}
start() {
this.world.start();
this.interval = setInterval(_ => this.update(this), 1 / 60);
}
stop() {
this.world.stop();
clearInterval(this.interval);
}
get playerCount() {
return this.players.size;
}