}
Game.prototype.start = function(ms) {
- this.timeout = setInterval(this.getNextFrame, ms);
+ var me = this;
+ var tmpfn = function() {me.getNextFrame()};
+ this.timeout = setInterval(tmpfn, ms);
}
Game.prototype.getNextFrame = function() {
- //
+ console.log(this);
var inputs = this.players.map(function(p) {return p.get_status();});
- this.state.updateState(inputs);
+ this.state.update(inputs);
var state = this.state.getState();
for(var i=0; i<this.players.length;i++) {
this.players[i].socket.send(i.toString() + ", " + state);
const WebSocket = require('ws');
-const wss = WebSocket.Server({port: WS_PORT});
+const wss = new WebSocket.Server({port: WS_PORT});
const Player = require('./player.js');
const Game = require('./game.js');
players = [];
-wss.on('connection', manage_incoming);
-
var manage_incoming = function(ws) {
var new_player = new Player(ws);
players.push(new_player);
- if(players.length > NUM_PLAYERS) {
+ if(players.length >= NUM_PLAYERS) {
// is the slicing necessary? I'm not sure I understand js's mechanisms without threads
game = new Game(players.slice(0, NUM_PLAYERS));
//
players = players.slice(NUM_PLAYERS);
}
}
+
+wss.on('connection', manage_incoming);
+