From 282073d9e16c10b284078c4fb19b0d249bd64dab Mon Sep 17 00:00:00 2001 From: Elijah Cohen Date: Thu, 2 May 2019 01:56:47 -0500 Subject: [PATCH] whoops, meant this for the last commit --- server/ball.js | 6 +++--- server/constants.js | 2 +- server/gamestate.js | 44 ++++++++++++++++++++++++-------------------- web/constants.js | 2 +- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/server/ball.js b/server/ball.js index 44c6084..640f22c 100644 --- a/server/ball.js +++ b/server/ball.js @@ -13,12 +13,12 @@ function Ball() { } Ball.prototype.speed_up = function() { - // this is ez with proportions var speed = Math.sqrt(this.dx*this.dx + this.dy*this.dy); if (speed > c.MAX_SPEED) speed = c.MAX_SPEED; - this.dx = (speed*this.dx)/(speed+c.SPEED_BUMP); - this.dy = (speed*this.dy)/(speed+c.SPEED_BUMP); + // fun trig stuff that i've messed up probably a few times now + this.dx = this.dx*(speed+c.SPEED_BUMP)/speed; + this.dy = this.dy*(speed+c.SPEED_BUMP)/speed; } Ball.prototype.get_angle = function() { diff --git a/server/constants.js b/server/constants.js index 539be0f..9ff4e05 100644 --- a/server/constants.js +++ b/server/constants.js @@ -3,7 +3,7 @@ var c = { // matchmaker WS_PORT: 6789, - NUM_PLAYERS: 3, + NUM_PLAYERS: 8, MS_PER_FRAME: 100, WAIT_TIME: 60000, // 1 minute MAX_GAMES: 5, // the most games allowed to go on at once, to be tweaked as needed for purposes diff --git a/server/gamestate.js b/server/gamestate.js index b3f7f73..4ac418d 100644 --- a/server/gamestate.js +++ b/server/gamestate.js @@ -6,6 +6,7 @@ const Coord = require('./coord.js'); const Ball = require('./ball.js'); const field = require('./field.js'); const Paddle = require('./paddles.js'); +const collisions = require('./collisions.js'); function Dead(id) { this.id = id; @@ -33,23 +34,6 @@ function starting_balls(n) { } -function nearest_point_on_line(c, ep) { - // finds the point on the line defined by ep closest to center c - if(ep.f.x == ep.s.x) { - // vertical line, undef slope - return new Coord(ep.f.x, c.y); - } - if(ep.f.y == ep.s.y) { - // horizontal line, zero slope - return new Coord(c.x, ep.f.y); - } - var sl = (ep.f.y-ep.s.y)/(ep.f.x-ep.s.x); - var sr = 1/sl; - var x_int = (sl*ep.f.x - sr*c.x + c.y - ep.f.y)/(sl-sr); - var y_int = sr*(x_int-c.x) + c.y; - return new Coord(x_int, y_int); -} - GameState.prototype.update = function(inputs) { // inputs is an array of the characters from all the players (even dead? yeah) // move the paddles @@ -88,7 +72,7 @@ GameState.prototype.update = function(inputs) { // rotate, reflect, rotate back var vel_coord = new Coord(ball.dx, ball.dy); vel_coord.rotate(-slope_angle); - vel_coord.x = -vel_coord.x; + vel_coord.y = -vel_coord.y; vel_coord.rotate(slope_angle); ball.dx = vel_coord.x; ball.dy = vel_coord.y; @@ -112,7 +96,7 @@ GameState.prototype.update = function(inputs) { // rotate, reflect, rotate back var vel_coord = new Coord(ball.dx, ball.dy); vel_coord.rotate(-slope_angle); - vel_coord.x = -vel_coord.x; + vel_coord.y = -vel_coord.y; // note: any 'too fast' errors will be solved in the 'speed_up' method, so i need not worry here if(paddle.direction == 'u') { vel_coord.x += c.PADDLE_MVT_BONUS; @@ -128,6 +112,8 @@ GameState.prototype.update = function(inputs) { } } } + + } // shrink the existing dead zones for the future for(var d of this.dead) { @@ -138,7 +124,6 @@ GameState.prototype.update = function(inputs) { // check for deaths // i don't need to check where any of the paddles are, I just need to check the spaces behind the paddles (±) - // JUST REWRITE HERE TO AVOID field.angles, I CAN JUST DO ARCTAN ON PLAYERPOINTS var zero = new Coord(0,0); var oobs = this.balls.filter(b => (b.coord.dist2(zero)>(c.BOARD_RADIUS+c.OOB_THRESH)**2)); var angs = livingzones.map(eps => eps.getAngles()); @@ -187,4 +172,23 @@ GameState.prototype.getState = function() { return theobject; } + +function nearest_point_on_line(c, ep) { + // finds the point on the line defined by ep closest to center c + if(ep.f.x == ep.s.x) { + // vertical line, undef slope + return new Coord(ep.f.x, c.y); + } + if(ep.f.y == ep.s.y) { + // horizontal line, zero slope + return new Coord(c.x, ep.f.y); + } + var sl = (ep.f.y-ep.s.y)/(ep.f.x-ep.s.x); + var sr = 1/sl; + var x_int = (sl*ep.f.x - sr*c.x + c.y - ep.f.y)/(sl-sr); + var y_int = sr*(x_int-c.x) + c.y; + return new Coord(x_int, y_int); +} + + module.exports = GameState; diff --git a/web/constants.js b/web/constants.js index cdd7d8b..add9fdd 100644 --- a/web/constants.js +++ b/web/constants.js @@ -3,7 +3,7 @@ var c = { // matchmaker WS_PORT: 6789, - NUM_PLAYERS: 3, + NUM_PLAYERS: 8, MS_PER_FRAME: 100, WAIT_TIME: 60000, // 1 minute MAX_GAMES: 5, // the most games allowed to go on at once, to be tweaked as needed for purposes -- 2.39.2