From c1965d96a4e01f1394217f7fea4369ddee4ef5a2 Mon Sep 17 00:00:00 2001 From: Elijah Cohen Date: Wed, 1 May 2019 00:45:06 -0500 Subject: [PATCH] idk commiting for the sake of it mostly, added proper angle stuff --- server/endpoints.js | 17 +++++++++++++++++ server/gamestate.js | 5 +++-- web/draw.js | 11 ++++++++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/server/endpoints.js b/server/endpoints.js index bd5b51c..bc08424 100644 --- a/server/endpoints.js +++ b/server/endpoints.js @@ -1,5 +1,7 @@ +const c = require('./constants.js'); + var Endpoints = function(f,s,id) { // f,s are first, second coordinates, in increasing angle // id corresponds to a player, or -1 or smth if n/a @@ -9,5 +11,20 @@ var Endpoints = function(f,s,id) { this.id = id; } +var AnglePair = function(f,s,id) { + this.f = f; + this.s = s; + this.id = id; +} + +Endpoints.prototype.getAngles = function() { + // gets an anglepair for the endpoints. does assume the first angle is before second + var fst = Math.atan2(this.f.y, this.f.x); + var snd = Math.atan2(this.s.y, this.s.x); + if(snd < fst) { + snd += 2*Math.PI; + } + return new AnglePair(fst-c.ANGLE_THRESH, snd+c.ANGLE_THRESH, this.id); +} module.exports = Endpoints; diff --git a/server/gamestate.js b/server/gamestate.js index eba3a8b..2462914 100644 --- a/server/gamestate.js +++ b/server/gamestate.js @@ -64,7 +64,7 @@ GameState.prototype.update = function(inputs) { // var endpoints = field.genAllEndpoints(this.numPlayers, this.dead); var livingzones = endpoints.filter(e => (e.id != -1)); - livingzones = livingzones.filter(e => this.dead.some(d => (d.id!=e.id))); // bad time complexity? + livingzones = livingzones.filter(e => !this.dead.some(d => (d.id==e.id))); // bad time complexity? 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) { @@ -134,7 +134,8 @@ GameState.prototype.update = function(inputs) { // 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 = field.angles(this.numPlayers, this.dead, c.ANGLE_THRESH); + var angs = livingzones.map(eps => eps.getAngles()); + //var angs = field.angles(this.numPlayers, this.dead, c.ANGLE_THRESH); for(var oob of oobs) { var oobth = oob.get_angle(); for(var ang of angs) { diff --git a/web/draw.js b/web/draw.js index cbad3a7..f6f0c7d 100644 --- a/web/draw.js +++ b/web/draw.js @@ -6,6 +6,7 @@ dwallcolor = 'rgb(200,0,0)'; wallcolor = 'rgb(100,100,0)'; pcolor = 'rgb(0,0,200)'; bcolor = 'rgb(100,100,100)'; +xcolor = 'rgb(200,0,200)'; // main function, given everything from the game state, draws on the given context @@ -18,8 +19,7 @@ var draw = function(state, ctx) { //console.log(state); var endpoints = genAllEndpoints(state.n, state.dead); - console.log(endpoints); - var livingzones = endpoints.filter(e => (e.id != -1) && (state.dead.some(d=>(d.id!=e.id)))); + var livingzones = endpoints.filter(e => (e.id != -1) && (!state.dead.some(d=>(d.id==e.id)))); var walls = endpoints.filter(e => (e.id==-1) || state.dead.some(d=>(d.id==e.id))); //draw walls for(var eps of walls) { @@ -29,16 +29,21 @@ var draw = function(state, ctx) { } drawLine(ctx, c, eps.f, eps.s); } + // do something to show the zones for my sanity + for(var lz of livingzones) { + drawLine(ctx, xcolor, lz.f, lz.s); + } // balls for(var b of state.balls) { drawBall(ctx, bcolor, b); } // finally the paddles... for(var eps of livingzones) { - var paddle = state.paddles.find(p => (p.id==ep.id)); //should be guaranteed? + var paddle = state.paddles.find(p => (p.id==eps.id)); //should be guaranteed? if(paddle === undefined) alert("UH OH, paddle somehow undefined"); // cool this is way simpler since we know these are all alive var pps = getPaddlePoints(paddle, eps); + console.log(pps); drawLine(ctx, pcolor, pps.f, pps.s); } } -- 2.39.2