]> git.eli173.com Git - pong_br/commitdiff
doesn't crash before a connection sweet
authorElijah Cohen <eli@eli173.com>
Sat, 27 Apr 2019 07:23:26 +0000 (02:23 -0500)
committerElijah Cohen <eli@eli173.com>
Sat, 27 Apr 2019 07:23:26 +0000 (02:23 -0500)
server/constants.js
server/coord.js
server/field.js
server/gamestate.js
server/matchmaker.js

index 910d5203e82804fad152833367251f12d9f54c9f..53b6c2cbf89f28a28fa5b43b9692e4cc330e835f 100644 (file)
@@ -5,6 +5,7 @@ var c = {
     WS_PORT: 6789,
     NUM_PLAYERS: 3,
     MS_PER_FRAME: 500,
+    WAIT_TIME: 60000, // 1 minute
     // gamestate
     DYING_TIME_IN_FRAMES: 100,
     BOARD_RADIUS: 10,
index 0cedeaef46b2c89c483668e957121d57ac413a36..3469220402189afd36ecfc2334bbd7aeb5c47046 100644 (file)
@@ -3,20 +3,20 @@
 
 
 
-var Coord(x,y) {
+var Coord = function(x,y) {
     this.x = x;
     this.y = y;
 }
 
 
-Coord.prototype.dist2(c2) {
+Coord.prototype.dist2 = function(c2) {
     // returns square of the distance
     var dx = this.x-c2.x;
     var dy = this.y-c2.y;
     return dx*dx + dy*dy;
 }
 
-Coord.prototype.rotate(th) {
+Coord.prototype.rotate = function(th) {
     // rotates about angle, returns new value
     var new_x = this.x*Math.cos(th) - this.y*Math.sin(th);
     var new_y = this.x*Math.sin(th) + this.y*Math.cos(th);
index 1fcae74d8ca7217debf3208210ff8a2cde2a2f7f..3f63978cbcdc34fec16cdab70cfc6bbcbb52ccef 100644 (file)
@@ -91,3 +91,4 @@ var angles = function(n, dead, thresh) {
     return angs;
 }
 
+module.exports = {angles: angles, genEndpoints: genEndpoints, endpointNegatives: endpointNegatives};
index 84e5f6ec39be4930f3467c97454c2a530ab3fd55..a5bb7193207426aa9cb3e1485bb43d4270207893 100644 (file)
@@ -4,6 +4,8 @@ const c = require('./constants.js');
 
 const Coord = require('./coord.js');
 const Ball = require('./ball.js');
+const field = require('./field.js');
+
 
 function Dead(id) {
     this.id = id;
@@ -20,8 +22,9 @@ function GameState(n) {
     }
     this.balls = [];
     for(var i=0;i<starting_balls(n);i++) {
-       this.balls.push(new Ball();)
+       this.balls.push(new Ball());
     }
+    this.field = field.genEndpoints(n,[]);
 }
 
 function starting_balls(n) {
@@ -60,8 +63,9 @@ GameState.prototype.update = function(inputs) {
        ball.coord.y += ball.dy;
     }
     //
-    var endpoints = genEndpoints(this.numPlayers, this.dead);
-    var borders = endpointNegatives(endpoints);
+    this.field = field.genEndpoints(this.numPlayers, this.dead);
+    var endpoints = this.field;
+    var borders = field.endpointNegatives(endpoints);
     var deadzones = endpoints.filter(ep => ep.isDead);
     var walls = borders.concat(deadzones);    
     // check for collisions
@@ -126,7 +130,7 @@ GameState.prototype.update = function(inputs) {
     // 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.dist2(zero)>(c.BOARD_RADIUS+c.OOB_THRESH)));
-    var angs = angles(this.numPlayers, this.dead, c.ANGLE_THRESH);
+    var angs = field.angles(this.numPlayers, this.dead, c.ANGLE_THRESH);
     for(var oob in oobs) {
        var oobth = oob.get_angle();
        for(var ang in angs) {
index 232df89b3f71ab6f8676f3303da920eb4c99cb3e..8201a9e39859fb63f2656f7724434b32efc638b5 100644 (file)
@@ -11,7 +11,7 @@ const Game = require('./game.js');
 
 players = [];
 
-
+timeout = null;
 
 var manage_incoming = function(ws) {
     var new_player = new Player(ws);