From: Elijah Cohen Date: Thu, 18 Apr 2019 07:34:33 +0000 (-0500) Subject: fixed some stuff, maybe it works? X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=b611e3171faabb261cb72be29351d383a5a63eca;p=pong_br fixed some stuff, maybe it works? still untested considering user inputs and whatnot --- diff --git a/server/game.js b/server/game.js index 9241cbe..1ea9ede 100644 --- a/server/game.js +++ b/server/game.js @@ -8,13 +8,15 @@ function Game(players) { } 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 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)); // @@ -28,3 +26,6 @@ var manage_incoming = function(ws) { players = players.slice(NUM_PLAYERS); } } + +wss.on('connection', manage_incoming); +