From b611e3171faabb261cb72be29351d383a5a63eca Mon Sep 17 00:00:00 2001 From: Elijah Cohen Date: Thu, 18 Apr 2019 02:34:33 -0500 Subject: [PATCH] fixed some stuff, maybe it works? still untested considering user inputs and whatnot --- server/game.js | 8 +++++--- server/matchmaker.js | 9 +++++---- 2 files changed, 10 insertions(+), 7 deletions(-) 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); + -- 2.39.2