]> git.eli173.com Git - pong_br/commitdiff
broke stuff, gonna fix the framerate issue before proceeding though
authorElijah Cohen <eli@eli173.com>
Thu, 2 May 2019 21:44:59 +0000 (16:44 -0500)
committerElijah Cohen <eli@eli173.com>
Thu, 2 May 2019 21:44:59 +0000 (16:44 -0500)
server/collisions.js
server/constants.js
server/gamestate.js
web/constants.js

index 19347338ec5b1b19720d562e4b8486b379dd3bfa..150132033ed3d5996186b9c7df2cbd6403bb845e 100644 (file)
@@ -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);
index a45093aeb67665e1bae87ebdb9a9625939fc9673..a5fdce4eb889e6fe622df8e3c1ae6d8830c68c69 100644 (file)
@@ -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
index b64e0aa1c865ba56a080d9a983060f422c01e585..52f63ddb94f2c31f1efb2a762c679caacd7d7150 100644 (file)
@@ -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<walls.length) && !collided; i++) {
-           var nearest = nearest_point_on_line(ball.coord, walls[i]);
-           var dist2 = ball.coord.dist2(nearest);
-           if(dist2 < (ball.radius*ball.radius)) {
-               // we have a collision!
-               collided = true;
-               var vec = [walls[i].f.x-walls[i].s.x, walls[i].f.y-walls[i].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;
-               vel_coord.rotate(slope_angle);
-               ball.dx = vel_coord.x;
-               ball.dy = vel_coord.y;
-               // increase speed slightly
-               ball.speed_up();
-           }  
-       }
-       for(var lz of livingzones) {
-           // get corresponding paddle
-           // should be guaranteed to find one.... so...
-           var paddle = this.paddles.find(p => 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)
index 1a53e89a66c1823462ca4fc9f7137e74a24231a8..884666f624ab237332be5eaaf0532178e190c140 100644 (file)
@@ -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