diff --git a/client/src/components/Game.vue b/client/src/components/Game.vue index 87f50ef..e2ae49d 100644 --- a/client/src/components/Game.vue +++ b/client/src/components/Game.vue @@ -93,9 +93,10 @@ export default { this.context.stroke() }, renderDebug (player) { - this.context.beginPath() const canvasX = this.canvas.width / 2 const canvasY = this.canvas.height / 2 + /* + this.context.beginPath() this.context.lineTo(canvasX, canvasY) this.context.lineTo(this.mouse.x, this.mouse.y) this.context.lineWidth = 1 @@ -111,12 +112,6 @@ export default { this.context.strokeStyle = 'yellow' this.context.stroke() - this.context.beginPath() - this.context.arc(this.mouse.x, this.mouse.y, 25, 0, 2 * Math.PI, false) - this.context.lineWidth = 1 - this.context.strokeStyle = 'yellow' - this.context.stroke() - const canvasX2 = this.canvas.width / 2 const canvasY2 = this.canvas.height / 2 this.context.beginPath() @@ -124,11 +119,18 @@ export default { this.context.lineWidth = 1 this.context.strokeStyle = 'purple' this.context.stroke() + */ this.context.fillText('player x: ' + player.x + ' y:' + player.y, 10, 10) this.context.fillText('a:' + player.angle + ' a_t' + player.targetAngle, 10, 20) this.context.fillText('canvasX: ' + canvasX + ' canvasY:' + canvasY, 10, 30) this.context.fillText('walls: ' + player.walls.length, 10, 40) + + this.context.beginPath() + this.context.arc(this.mouse.x, this.mouse.y, 25, 0, 2 * Math.PI, false) + this.context.lineWidth = 1 + this.context.strokeStyle = player.color + this.context.stroke() }, mouseEvent (event) { var rect = this.canvas.getBoundingClientRect() diff --git a/server/src/main/java/gltronic/tronio/business/GameManager.java b/server/src/main/java/gltronic/tronio/business/GameManager.java index 7dab49a..b70ee04 100644 --- a/server/src/main/java/gltronic/tronio/business/GameManager.java +++ b/server/src/main/java/gltronic/tronio/business/GameManager.java @@ -71,6 +71,9 @@ public class GameManager implements IGameManager { // COLLISIONS game.getPlayers().forEach((id2, player2) -> { for (var i = 0; i < player2.getWalls().size() - 2; i++) { + // Pour evité la collision avec un mur venant d'être placé par le même joueur + if (id.equals(id2) && i >= player2.getWalls().size() - 4) break; + Wall wallA = player2.getWalls().get(i); Wall wallB = player2.getWalls().get(i + 1); if (isCloseToWall(wallA.getX(), wallA.getY(), wallB.getX(), wallB.getY(), player.getX(), player.getY(), @@ -101,7 +104,11 @@ public class GameManager implements IGameManager { player.setY(player.getY() + game.getSettings().getPlayerSpeed() * Math.sin(player.getAngle())); }); - SocketUtils.broadcast(game, "gameUpdate", new ObjectMapper().writeValueAsString(game.getPlayers().values())); + // Broadcast une fois sur deux + if (game.isUpdateNeeded()) { + SocketUtils.broadcast(game, "gameUpdate", new ObjectMapper().writeValueAsString(game.getPlayers().values())); + game.setUpdateNeeded(false); + } else game.setUpdateNeeded(true); } private void killPlayer(String id) { @@ -127,11 +134,15 @@ public class GameManager implements IGameManager { } private boolean isCrossingLine (double xa, double ya, double xb, double yb, double xc, double yc, double radius) { + /* var a = xc - xa; var b = xb - xa; var c = yc - ya; var d = yb - ya; var result = (a * d - b * c) / Math.sqrt(Math.pow(xa - xb, 2) + Math.pow(ya - yb, 2)); + */ + + var result = Math.abs((yb - ya) * xc - (xb - xa) * yc + xb * ya - yb * xa)/ Math.sqrt(Math.pow(xb - xa, 2) + Math.pow(yb - ya, 2)); return result < radius; } diff --git a/server/src/main/java/gltronic/tronio/model/Game.java b/server/src/main/java/gltronic/tronio/model/Game.java index 174613a..9b6e17c 100644 --- a/server/src/main/java/gltronic/tronio/model/Game.java +++ b/server/src/main/java/gltronic/tronio/model/Game.java @@ -16,8 +16,10 @@ public class Game { private Map players; private Map sessions; private GameSettings settings; + private boolean updateNeeded; public Game() { + this.updateNeeded = false; this.players = new HashMap<>(); this.sessions = new HashMap<>(); this.settings = new GameSettings(); diff --git a/server/target/classes/gltronic/tronio/business/GameManager.class b/server/target/classes/gltronic/tronio/business/GameManager.class index 5202f6d..6644b40 100644 Binary files a/server/target/classes/gltronic/tronio/business/GameManager.class and b/server/target/classes/gltronic/tronio/business/GameManager.class differ diff --git a/server/target/classes/gltronic/tronio/model/Game.class b/server/target/classes/gltronic/tronio/model/Game.class index f42f641..f4e57ec 100644 Binary files a/server/target/classes/gltronic/tronio/model/Game.class and b/server/target/classes/gltronic/tronio/model/Game.class differ