diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2018-06-23 22:28:51 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2018-06-23 22:28:59 +0200 |
commit | a1e2e25eab551f3a8f35152dd720b37d2b828b07 (patch) | |
tree | 1f265e26034920fe96811d485d82330142e33473 | |
parent | 114502685ecbe9484aee3907ee8c28741bd5b27b (diff) |
Correct handling of ballvec
-rw-r--r-- | game.js | 8 | ||||
-rwxr-xr-x | server.js | 2 |
2 files changed, 8 insertions, 2 deletions
@@ -145,6 +145,11 @@ function openGame() { pad2Vel = vel; }); + socket.on("ballvec", function(x, y, vx, vy) { + ballX = x; ballY = y; + ballVX = vx; ballVY = vy; + }); + socket.emit("open", gameId); } @@ -225,7 +230,8 @@ function advancePhysics(deltaT) { ballVX = -ballVX; } - if ((ballX < 0.5) ^ (newballX < 0.5)) { + // If the ball has come to our side, send a ballvec + if (ballX >= 0.5 && newballX < 0.5) { sendBallvec = true; } @@ -135,7 +135,7 @@ io.on("connection", (conn) => { if (!gameobj) return; for (const p of gameobj.pl) { if (p != conn) { - p.emit("ballvec", x, y, vx, vy); + p.emit("ballvec", 1 - x, y, -vx, vy); } } }); |