-var Coord(x,y) {
+var Coord = function(x,y) {
this.x = x;
this.y = y;
}
-Coord.prototype.dist2(c2) {
+Coord.prototype.dist2 = function(c2) {
// returns square of the distance
var dx = this.x-c2.x;
var dy = this.y-c2.y;
return dx*dx + dy*dy;
}
-Coord.prototype.rotate(th) {
+Coord.prototype.rotate = function(th) {
// rotates about angle, returns new value
var new_x = this.x*Math.cos(th) - this.y*Math.sin(th);
var new_y = this.x*Math.sin(th) + this.y*Math.cos(th);
const Coord = require('./coord.js');
const Ball = require('./ball.js');
+const field = require('./field.js');
+
function Dead(id) {
this.id = id;
}
this.balls = [];
for(var i=0;i<starting_balls(n);i++) {
- this.balls.push(new Ball();)
+ this.balls.push(new Ball());
}
+ this.field = field.genEndpoints(n,[]);
}
function starting_balls(n) {
ball.coord.y += ball.dy;
}
//
- var endpoints = genEndpoints(this.numPlayers, this.dead);
- var borders = endpointNegatives(endpoints);
+ this.field = field.genEndpoints(this.numPlayers, this.dead);
+ var endpoints = this.field;
+ var borders = field.endpointNegatives(endpoints);
var deadzones = endpoints.filter(ep => ep.isDead);
var walls = borders.concat(deadzones);
// check for collisions
// i don't need to check where any of the paddles are, I just need to check the spaces behind the paddles (±)
var zero = new Coord(0,0);
var oobs = this.balls.filter(b => (b.dist2(zero)>(c.BOARD_RADIUS+c.OOB_THRESH)));
- var angs = angles(this.numPlayers, this.dead, c.ANGLE_THRESH);
+ var angs = field.angles(this.numPlayers, this.dead, c.ANGLE_THRESH);
for(var oob in oobs) {
var oobth = oob.get_angle();
for(var ang in angs) {