From 434372c94a5465de49165cb93e5cba7f36192799 Mon Sep 17 00:00:00 2001 From: Elijah Cohen Date: Tue, 30 Apr 2019 15:36:41 -0500 Subject: [PATCH] lotta debugging, about to make structural changes genendpoints should now produce both the space endpoints and the wall endpoints --- server/constants.js | 6 +++--- server/field.js | 5 +++-- server/game.js | 2 +- server/gamestate.js | 25 +++++++++++++++++-------- server/player.js | 2 +- web/constants.js | 2 +- web/draw.js | 16 +++++++++------- web/field.js | 5 +++-- web/main.js | 4 +++- web/play.html | 8 +++++--- 10 files changed, 46 insertions(+), 29 deletions(-) diff --git a/server/constants.js b/server/constants.js index f01ff59..539be0f 100644 --- a/server/constants.js +++ b/server/constants.js @@ -4,7 +4,7 @@ var c = { // 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 @@ -14,8 +14,8 @@ var c = { 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, diff --git a/server/field.js b/server/field.js index abd3124..dbcf103 100644 --- a/server/field.js +++ b/server/field.js @@ -20,8 +20,9 @@ var genEndpoints = function(n ,dead) { 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(e.id==i)); if((deadStatus !== undefined) && (deadStatus.time > 0)) { diff --git a/server/game.js b/server/game.js index ac85f31..34895ae 100644 --- a/server/game.js +++ b/server/game.js @@ -23,7 +23,7 @@ Game.prototype.getNextFrame = function() { state.id = 0; for(var i=0; i ep.isDead); var walls = borders.concat(deadzones); @@ -123,24 +124,32 @@ GameState.prototype.update = function(inputs) { } } } + // 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)); diff --git a/server/player.js b/server/player.js index a0d24fa..1b5aead 100644 --- a/server/player.js +++ b/server/player.js @@ -25,7 +25,7 @@ Player.prototype.listener = function(msg) { } 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); } } diff --git a/web/constants.js b/web/constants.js index b67c956..cdd7d8b 100644 --- a/web/constants.js +++ b/web/constants.js @@ -4,7 +4,7 @@ var c = { // 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 diff --git a/web/draw.js b/web/draw.js index 5de5506..72086f0 100644 --- a/web/draw.js +++ b/web/draw.js @@ -11,12 +11,14 @@ bcolor = 'rgb(100,100,100)'; // 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)); @@ -33,7 +35,7 @@ var draw = function(state, ctx) { 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? @@ -48,6 +50,7 @@ var draw = function(state, ctx) { 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; @@ -63,16 +66,16 @@ var getPaddlePoints = function(paddle, enclosing) { -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; @@ -86,7 +89,6 @@ var drawLine(ctx, color, c1, c2) { 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(); } diff --git a/web/field.js b/web/field.js index b6e2910..4316922 100644 --- a/web/field.js +++ b/web/field.js @@ -16,8 +16,9 @@ var genEndpoints = function(n ,dead) { 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(e.id==i)); if((deadStatus !== undefined) && (deadStatus.time > 0)) { diff --git a/web/main.js b/web/main.js index 8fc137d..f11df3f 100644 --- a/web/main.js +++ b/web/main.js @@ -4,6 +4,8 @@ var prefixurl = "ws://localhost:6789"; theSocket = null; +var module = {}; + var main = function() { // starts everything, gets us going, setup ish var canvas = document.getElementById('c'); if(!canvas.getContext) { @@ -14,7 +16,7 @@ var main = function() { // starts everything, gets us going, setup ish 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); diff --git a/web/play.html b/web/play.html index 9adec06..e238a12 100644 --- a/web/play.html +++ b/web/play.html @@ -2,10 +2,12 @@ Pong Battle Royale - - - + + + + +