add basic game classes

This commit is contained in:
Asraelite 2016-03-21 17:12:26 +00:00
parent ebcee954bf
commit bb9a493450
11 changed files with 137 additions and 6 deletions

View file

@ -0,0 +1,38 @@
'use strict';
const World = require('./world');
class Room {
constructor() {
this.players = new Set();
this.teamA = new Set();
this.teamB = new Set();
this.world = new World();
this.name = (Math.random() * 100000 | 0).toString(36);
}
add(player) {
player.room = this;
player.connection.room = this.name;
this.players.add(player);
this.setTeam(player, this.teamA.size > this.teamB.size ? 'b' : 'a');
this.world.addPlayer(player);
}
setTeam(player, team) {
this.teamA.delete(player);
this.teamB.delete(player);
(team == 'a' ? this.teamA : this.teamB).add(player);
player.team = team;
}
get playerCount() {
return this.players.size;
}
get full() {
return this.playerCount >= 8;
}
}
module.exports = Room;

View file

View file

@ -0,0 +1,9 @@
'use strict';
class Body {
constructor() {
}
}
module.exports = Body;

View file

@ -0,0 +1,35 @@
'use strict';
const Ship = require('./ship.js');
class World {
constructor() {
this.box2d = false;
this.bodies = new Set();
this.structures = new Set();
this.asteroids = new Set();
this.ships = new Map();
this.players = new Set();
}
addPlayer(player) {
this.players.add(player);
this.ships.set(player, new Ship(player));
}
removePlayer(player) {
removeBody(player.ship);
this.ships.delete(player);
this.players.delete(player);
}
removeBody(body) {
// Remove from Box2d.
}
tick() {
}
}
module.exports = World;

View file

View file

@ -0,0 +1,13 @@
'use strict';
const Body = require('./body.js');
class Ship extends Body {
constructor(player) {
super();
this.player = player;
}
}
module.exports = Ship;

View file