// matchmaker
WS_PORT: 6789,
NUM_PLAYERS: 3,
- MS_PER_FRAME: 500,
+ MS_PER_FRAME: 100,
WAIT_TIME: 60000, // 1 minute
MAX_GAMES: 5, // the most games allowed to go on at once, to be tweaked as needed for purposes
// gamestate
ANGLE_THRESH: 0.2, //radians, needs to acct for various rotatings going on... can prolly wing it
PADDLE_MVT_BONUS: 0.1, // why this value? who knows. the extra speed from paddles in motion
// ball
- MIN_INIT: 3,
- MAX_INIT: 5, // initial speed constraints
+ MIN_INIT: 0.1,
+ MAX_INIT: 1, // initial speed constraints
BALL_RADIUS: 0.5,
MAX_SPEED: 15,
SPEED_BUMP: 0.2,
players_length += d.time/c.DYING_TIME_IN_FRAMES;
}
var theta = 0;
- var dtheta = players_length/(2*Math.PI);
- var coord = new Coord(c.BOARD_RADIUS,0);
+ var dtheta = (2*Math.PI)/players_length;
+ // so my dumb ass forgot that 'r' isn't a thing, so I'm setting it from a proper place here...
+ var r = c.BOARD_RADIUS;
for(var i=0; i<n; i++) {
var deadStatus = dead.find(e=>(e.id==i));
if((deadStatus !== undefined) && (deadStatus.time > 0)) {
state.id = 0;
for(var i=0; i<this.players.length;i++) {
state.id = i;
- this.players[i].socket.send(JSON.stringify(state));
+ this.players[i].send_data(JSON.stringify(state));
}
}
}
//
var endpoints = field.genEndpoints(this.numPlayers, this.dead);
+ //console.log(endpoints);
var borders = field.endpointNegatives(endpoints);
var deadzones = endpoints.filter(ep => ep.isDead);
var walls = borders.concat(deadzones);
}
}
}
+ // shrink the existing dead zones for the future
+ for(var d of this.dead) {
+ d.time--;
+ }
+
// check for deaths
// OK I'M HERE AFAICT
// 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.coord.dist2(zero)>(c.BOARD_RADIUS+c.OOB_THRESH)));
+ 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);
for(var oob of oobs) {
var oobth = oob.get_angle();
for(var ang of angs) {
// normalise angle pair...
// this gon be inefficient sigh
- var a1 = ang.f;
- var a2 = ang.s;
- while(oobth > (a1-2*Math.PI))
- oobth -= 2*Math.PI;
- while( a2 > (oobth-2*Math.PI))
- a2 -= 2*Math.PI;
- if((a2-a1) < 2*Math.PI) { // it's in between! (I should check my math...)
+ var a1 = ang.f % (2*Math.PI);
+ var a2 = ang.s % (2*Math.PI);
+ var ab = oobth % (2*Math.PI);
+ if(a1 > a2) {
+ a2 += 2*Math.PI;
+ }
+ if (a1 > ab) {
+ ab += 2*Math.PI;
+ }
+ if((ab > a1) && (ab < a2)) {
// check if not already dead (in case multi balls out at same time etc)
if(!this.dead.some(x => x.id == ang.id)) {
this.dead.push(new Dead(ang.id));
}
Player.prototype.send_data = function(data) {
- if(this.socket.readyState==1) { // TODO: replace the '1' with the proper identifier (the ready state constant)
+ if(this.socket.readyState==this.socket.OPEN) {
this.socket.send(data);
}
}
// matchmaker
WS_PORT: 6789,
NUM_PLAYERS: 3,
- MS_PER_FRAME: 500,
+ MS_PER_FRAME: 100,
WAIT_TIME: 60000, // 1 minute
MAX_GAMES: 5, // the most games allowed to go on at once, to be tweaked as needed for purposes
// gamestate
// main function, given everything from the game state, draws on the given context
var draw = function(state, ctx) {
clearCanvas(ctx);
+
// okay, gotta get the endpoints, then draw the walls,
// then draw the balls,
// then finally the hard part is the paddles
+ //console.log(state);
var theEndpoints = genEndpoints(state.n, state.dead);
var negatives = endpointNegatives(theEndpoints);
-
+ console.log(theEndpoints);
// dead walls
for(var ep of theEndpoints) {
var deadOption = state.dead.find(d => (d.id==ep.id));
drawBall(ctx, bcolor, b);
}
// finally the paddles...
- for(var ep of endpoints) {
+ for(var ep of theEndpoints) {
var paddleOption = state.paddles.find(p => (p.id == ep.id));
if(paddleOption !== undefined) {
// should probably make sure it's not dead?
var getPaddlePoints = function(paddle, enclosing) {
// returns an endpoints object for the paddle
// given the desired width of said paddle and the enclosing endpoints
+ console.log(enclosing);
var encl_len = dist(enclosing.f, enclosing.s);
var pspace_len = encl_len - (2*c.WIDTH_RATIO*encl_len);
var place_on_pspace = pspace_len*(paddle.position+1)/2;
-var drawBall(ctx, color, c) {
+var drawBall = function(ctx, color, coord) {
ctx.save();
ctx.fillStyle = bcolor;
ctx.beginPath();
- ctx.arc(c.x, c.y, BALL_RADIUS, 0, 2*Math.PI, false);
+ ctx.arc(coord.x, coord.y, c.BALL_RADIUS, 0, 2*Math.PI, false);
ctx.fill();
ctx.restore();
}
-var drawLine(ctx, color, c1, c2) {
+var drawLine = function(ctx, color, c1, c2) {
// draws a line from c1 to c2 in color
ctx.save();
ctx.strokeStyle = color;
var clearCanvas = function(ctx) {
ctx.save();
- ctx.transform(1,0,0,1,0,0);
- ctx.clearRect(0,0,cxt.canvas.width, ctx.canvas.height);
+ ctx.clearRect(-ctx.canvas.width, -ctx.canvas.height, ctx.canvas.width*2, ctx.canvas.height*2);
ctx.restore();
}
players_length += d.time/c.DYING_TIME_IN_FRAMES;
}
var theta = 0;
- var dtheta = players_length/(2*Math.PI);
- var coord = new Coord(c.BOARD_RADIUS,0);
+ var dtheta = (2*Math.PI)/players_length;
+ // same bs with the 'r'...
+ var r = c.BOARD_RADIUS;
for(var i=0; i<n; i++) {
var deadStatus = dead.find(e=>(e.id==i));
if((deadStatus !== undefined) && (deadStatus.time > 0)) {
theSocket = null;
+var module = {};
+
var main = function() { // starts everything, gets us going, setup ish
var canvas = document.getElementById('c');
if(!canvas.getContext) {
canvas.height = window.innerHeight;
ctx = canvas.getContext('2d');
// change the 1's to zoom in i think.. todo
- ctx.transform(1, 0, 0, 1, ctx.width/2, ctx.height/2);
+ ctx.transform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2); // change to setTransform?
theSocket = new WebSocket(prefixurl);
<html>
<head>
<title>Pong Battle Royale</title>
- <script type="text/javascript" src="main.js"></script>
- <script type="text/javascript" src="draw.js"></script>
- <script type="text/javascript" src="coord.js"></script>
<script type="text/javascript" src="constants.js"></script>
+ <script type="text/javascript" src="coord.js"></script>
+ <script type="text/javascript" src="draw.js"></script>
+ <script type="text/javascript" src="main.js"></script>
+ <script type="text/javascript" src="field.js"></script>
+ <script type="text/javascript" src="endpoints.js"></script>
<style type="text/css">
body { background-color: black; }
#c {