]> git.eli173.com Git - pong_br/commitdiff
fixed some stuff, maybe it works?
authorElijah Cohen <eli@eli173.com>
Thu, 18 Apr 2019 07:34:33 +0000 (02:34 -0500)
committerElijah Cohen <eli@eli173.com>
Thu, 18 Apr 2019 07:34:33 +0000 (02:34 -0500)
still untested considering user inputs and whatnot

server/game.js
server/matchmaker.js

index 9241cbe7e7b957b9abb326af9536b4fb89b683d7..1ea9ede113210adfedd346d7ab6111173751bb97 100644 (file)
@@ -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<this.players.length;i++) {
        this.players[i].socket.send(i.toString() + ", " + state);
index ed7c2b63a2b278dd0274a0b46af1e187e5e666e1..29f36a0824a9220b75c56acb8b4e69ed937855f5 100644 (file)
@@ -5,7 +5,7 @@ const MS_PER_FRAME = 500;
 
 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');
@@ -13,13 +13,11 @@ 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));
        //
@@ -28,3 +26,6 @@ var manage_incoming = function(ws) {
        players = players.slice(NUM_PLAYERS);
     }
 }
+
+wss.on('connection', manage_incoming);
+