+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
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;
//
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) {
// 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) {
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
//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) {
}
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);
}
}