]> git.eli173.com Git - pong_br/commitdiff
begin work on some stuff, nothing too consequential, just committing
authorElijah Cohen <eli@eli173.com>
Wed, 1 May 2019 18:24:33 +0000 (13:24 -0500)
committerElijah Cohen <eli@eli173.com>
Wed, 1 May 2019 18:24:33 +0000 (13:24 -0500)
server/coord.js
server/gamestate.js
web/draw.js
web/play.html

index 3469220402189afd36ecfc2334bbd7aeb5c47046..5d4b6657ce38432fc7603a968d1128ec427ce747 100644 (file)
@@ -16,6 +16,11 @@ Coord.prototype.dist2 = function(c2) {
     return dx*dx + dy*dy;
 }
 
+Coord.prototype.dist2origin = function() {
+    // kinda hacky that this exists, I know
+    return this.x*this.x + this.y*this.y;
+}
+
 Coord.prototype.rotate = function(th) {
     // rotates about angle, returns new value
     var new_x = this.x*Math.cos(th) - this.y*Math.sin(th);
index 9681269f385ff7c46454b99a7dcb8b13f986f04a..b3f7f73ec6bf551ba5745ec2f627172a7c0e8c32 100644 (file)
@@ -68,8 +68,15 @@ GameState.prototype.update = function(inputs) {
     var walls = endpoints.filter(e => (e.id == -1) || this.dead.some(d => (d.id==e.id)));
     // check for collisions
     for(var ball of this.balls) {
-       // (check the fixt edges first, then the paddles I guess
        var collided = false;
+       // first, see if the ball is moving towards the center (should solve most problems with things
+       var currd2 = ball.coord.dist2origin();
+       var nextd2 = new Coord(ball.coord.x + ball.dx, ball.coord.y + ball.dy).dist2origin();
+       if(nextd2 < currd2)
+           continue;
+
+       // 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);
index 31f45dcc937111a2a4c5b44215eb087628aba566..a26a31c7edd5c3cd33e01044432700581f472333 100644 (file)
@@ -31,7 +31,7 @@ var draw = function(state, ctx) {
     }
     // do something to show the zones for my sanity
     for(var lz of livingzones) {
-       //drawLine(ctx, xcolor, lz.f, lz.s);
+       drawLine(ctx, xcolor, lz.f, lz.s);
     }
     // balls
     for(var b of state.balls) {
index e238a124820e0b7177ff1c83671e932a3a03e276..c7ab97cb539580b140c7e5fad3c2f45be11ffc91 100644 (file)
@@ -1,4 +1,5 @@
 <!doctype html>
+<meta charset='utf-8'>
 <html>
   <head>
     <title>Pong Battle Royale</title>