From a1e2e25eab551f3a8f35152dd720b37d2b828b07 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sat, 23 Jun 2018 22:28:51 +0200 Subject: Correct handling of ballvec --- game.js | 8 +++++++- server.js | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/game.js b/game.js index bd2b288..a2d5552 100644 --- a/game.js +++ b/game.js @@ -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; } diff --git a/server.js b/server.js index 47896e8..73add35 100755 --- a/server.js +++ b/server.js @@ -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); } } }); -- cgit v1.2.3-70-g09d2