From: Elijah Cohen Date: Thu, 2 May 2019 21:44:59 +0000 (-0500) Subject: broke stuff, gonna fix the framerate issue before proceeding though X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=fa120593c3f15e5e745dd1d6016e89426b889cac;p=pong_br broke stuff, gonna fix the framerate issue before proceeding though --- diff --git a/server/collisions.js b/server/collisions.js index 1934733..1501320 100644 --- a/server/collisions.js +++ b/server/collisions.js @@ -67,8 +67,9 @@ var handleWalls = function(ball, walls) { // wall is an endpoints for(var wall of walls) { var next_spot = new Coord(ball.coord.x + ball.dx, ball.coord.y + ball.dy); - if(segments_intersect(walls, new Endpoints(ball.coord, next_spot))) { + if(segments_intersect(wall, new Endpoints(ball.coord, next_spot))) { //there's a collision + console.log("int"); var wall_normal = new Coord((wall.f.x+wall.s.x)/2, (wall.f.y+wall.s.y)/2); // given by the midpoint var normal_angle = Math.atan2(wall_normal.x, wall_normal.y); var vel_vec = new Coord(ball.dx, ball.dy); diff --git a/server/constants.js b/server/constants.js index a45093a..a5fdce4 100644 --- a/server/constants.js +++ b/server/constants.js @@ -10,7 +10,7 @@ var c = { // gamestate DYING_TIME_IN_FRAMES: 100, BOARD_RADIUS: 10, - OOB_THRESH: 1, // out-of-bounds threshold + OOB_THRESH: 4, // out-of-bounds threshold 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 diff --git a/server/gamestate.js b/server/gamestate.js index b64e0aa..52f63dd 100644 --- a/server/gamestate.js +++ b/server/gamestate.js @@ -62,60 +62,13 @@ GameState.prototype.update = function(inputs) { // below here probably requires changes // (check the fixt edges first, then the paddles I guess - for(var i=0; (i p.id ==lz.id); - if((paddle !== undefined) && !collided) { - var padends = paddle.getPaddlePoints(lz); - var nearest = nearest_point_on_line(ball.coord, padends); - var dist2 = ball.coord.dist2(nearest); - if(dist2 < (ball.radius*ball.radius)) { - // we have a collision! - collided = true; - var vec = [padends.f.x-padends.s.x, padends.f.y-padends.s.y]; - var slope_angle = Math.atan2(vec[1],vec[0]); - // rotate, reflect, rotate back - var vel_coord = new Coord(ball.dx, ball.dy); - vel_coord.rotate(-slope_angle); - vel_coord.y = -vel_coord.y; - // note: any 'too fast' errors will be solved in the 'speed_up' method, so i need not worry here - if(paddle.direction == 'u') { - vel_coord.x += c.PADDLE_MVT_BONUS; - } - else if(paddle.direction == 'd') { - vel_coord.x -= c.PADDLE_MVT_BONUS; - } - vel_coord.rotate(slope_angle); - ball.dx = vel_coord.x; - ball.dy = vel_coord.y; - // increase speed slightly - ball.speed_up(); - } - } - } - - + if(collisions.handleWalls(ball, walls)) + continue; + if(collisions.handlePaddles(balls, livingzones, this.paddles)) + continue; + // i put that last continue but there's nothing left to do... } + // shrink the existing dead zones for the future for(var d of this.dead) { if(d.time > 0) diff --git a/web/constants.js b/web/constants.js index 1a53e89..884666f 100644 --- a/web/constants.js +++ b/web/constants.js @@ -10,7 +10,7 @@ var c = { // gamestate DYING_TIME_IN_FRAMES: 100, BOARD_RADIUS: 10, - OOB_THRESH: 1, // out-of-bounds threshold + OOB_THRESH: 4, // out-of-bounds threshold 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