From ff6dddb3c2e579ff5095caf211943f167f48ac45 Mon Sep 17 00:00:00 2001 From: Elijah Cohen Date: Sat, 27 Apr 2019 02:23:26 -0500 Subject: [PATCH] doesn't crash before a connection sweet --- server/constants.js | 1 + server/coord.js | 6 +++--- server/field.js | 1 + server/gamestate.js | 12 ++++++++---- server/matchmaker.js | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/server/constants.js b/server/constants.js index 910d520..53b6c2c 100644 --- a/server/constants.js +++ b/server/constants.js @@ -5,6 +5,7 @@ var c = { WS_PORT: 6789, NUM_PLAYERS: 3, MS_PER_FRAME: 500, + WAIT_TIME: 60000, // 1 minute // gamestate DYING_TIME_IN_FRAMES: 100, BOARD_RADIUS: 10, diff --git a/server/coord.js b/server/coord.js index 0cedeae..3469220 100644 --- a/server/coord.js +++ b/server/coord.js @@ -3,20 +3,20 @@ -var Coord(x,y) { +var Coord = function(x,y) { this.x = x; this.y = y; } -Coord.prototype.dist2(c2) { +Coord.prototype.dist2 = function(c2) { // returns square of the distance var dx = this.x-c2.x; var dy = this.y-c2.y; return dx*dx + dy*dy; } -Coord.prototype.rotate(th) { +Coord.prototype.rotate = function(th) { // rotates about angle, returns new value var new_x = this.x*Math.cos(th) - this.y*Math.sin(th); var new_y = this.x*Math.sin(th) + this.y*Math.cos(th); diff --git a/server/field.js b/server/field.js index 1fcae74..3f63978 100644 --- a/server/field.js +++ b/server/field.js @@ -91,3 +91,4 @@ var angles = function(n, dead, thresh) { return angs; } +module.exports = {angles: angles, genEndpoints: genEndpoints, endpointNegatives: endpointNegatives}; diff --git a/server/gamestate.js b/server/gamestate.js index 84e5f6e..a5bb719 100644 --- a/server/gamestate.js +++ b/server/gamestate.js @@ -4,6 +4,8 @@ const c = require('./constants.js'); const Coord = require('./coord.js'); const Ball = require('./ball.js'); +const field = require('./field.js'); + function Dead(id) { this.id = id; @@ -20,8 +22,9 @@ function GameState(n) { } this.balls = []; for(var i=0;i ep.isDead); var walls = borders.concat(deadzones); // check for collisions @@ -126,7 +130,7 @@ GameState.prototype.update = function(inputs) { // i don't need to check where any of the paddles are, I just need to check the spaces behind the paddles (±) var zero = new Coord(0,0); var oobs = this.balls.filter(b => (b.dist2(zero)>(c.BOARD_RADIUS+c.OOB_THRESH))); - var angs = angles(this.numPlayers, this.dead, c.ANGLE_THRESH); + var angs = field.angles(this.numPlayers, this.dead, c.ANGLE_THRESH); for(var oob in oobs) { var oobth = oob.get_angle(); for(var ang in angs) { diff --git a/server/matchmaker.js b/server/matchmaker.js index 232df89..8201a9e 100644 --- a/server/matchmaker.js +++ b/server/matchmaker.js @@ -11,7 +11,7 @@ const Game = require('./game.js'); players = []; - +timeout = null; var manage_incoming = function(ws) { var new_player = new Player(ws); -- 2.39.2