From: Elijah Cohen <eli@eli173.com> 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<walls.length) && !collided; i++) { var nearest = nearest_point_on_line(ball.coord, walls[i]); var dist2 = ball.coord.dist2(nearest); diff --git a/web/draw.js b/web/draw.js index 31f45dc..a26a31c 100644 --- a/web/draw.js +++ b/web/draw.js @@ -31,7 +31,7 @@ var draw = function(state, ctx) { } // do something to show the zones for my sanity for(var lz of livingzones) { - //drawLine(ctx, xcolor, lz.f, lz.s); + drawLine(ctx, xcolor, lz.f, lz.s); } // balls for(var b of state.balls) { diff --git a/web/play.html b/web/play.html index e238a12..c7ab97c 100644 --- a/web/play.html +++ b/web/play.html @@ -1,4 +1,5 @@ <!doctype html> +<meta charset='utf-8'> <html> <head> <title>Pong Battle Royale</title>