From: Elijah Cohen Date: Wed, 1 May 2019 18:24:33 +0000 (-0500) Subject: begin work on some stuff, nothing too consequential, just committing X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=4d2fe7567333b05c9317acb15ac3387b1bbaa58a;p=pong_br begin work on some stuff, nothing too consequential, just committing --- diff --git a/server/coord.js b/server/coord.js index 3469220..5d4b665 100644 --- a/server/coord.js +++ b/server/coord.js @@ -16,6 +16,11 @@ Coord.prototype.dist2 = function(c2) { return dx*dx + dy*dy; } +Coord.prototype.dist2origin = function() { + // kinda hacky that this exists, I know + return this.x*this.x + this.y*this.y; +} + Coord.prototype.rotate = function(th) { // rotates about angle, returns new value var new_x = this.x*Math.cos(th) - this.y*Math.sin(th); diff --git a/server/gamestate.js b/server/gamestate.js index 9681269..b3f7f73 100644 --- a/server/gamestate.js +++ b/server/gamestate.js @@ -68,8 +68,15 @@ GameState.prototype.update = function(inputs) { var walls = endpoints.filter(e => (e.id == -1) || this.dead.some(d => (d.id==e.id))); // check for collisions for(var ball of this.balls) { - // (check the fixt edges first, then the paddles I guess var collided = false; + // first, see if the ball is moving towards the center (should solve most problems with things + var currd2 = ball.coord.dist2origin(); + var nextd2 = new Coord(ball.coord.x + ball.dx, ball.coord.y + ball.dy).dist2origin(); + if(nextd2 < currd2) + continue; + + // below here probably requires changes + // (check the fixt edges first, then the paddles I guess for(var i=0; (i + Pong Battle Royale