From ccb2248d468852e5f7f88dcbed10fd00efa4b3d2 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 10 Apr 2016 17:21:43 +0200 Subject: Fix collision calculation for walls and stopped player self starting path --- src/ch/epfl/xblast/server/GameState.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/ch') diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java index 2818f26..7d921ee 100644 --- a/src/ch/epfl/xblast/server/GameState.java +++ b/src/ch/epfl/xblast/server/GameState.java @@ -241,7 +241,7 @@ public final class GameState { */ private static Sq nextPath(Player p0, Direction requestedDir) { return GameState.newPath( - Player.DirectedPosition.moving(p0.directedPositions().head()), + p0.directedPositions(), GameState.nextDirection(p0, requestedDir)); } @@ -253,10 +253,13 @@ public final class GameState { * @return the new path */ private static Sq newPath(Sq p0, Direction newDir) { + if (newDir == p0.head().direction()) + return p0; + if (p0.head().direction().isPerpendicularTo(newDir)) - return GameState.pivotPath(p0, newDir); - else - return Player.DirectedPosition.moving(new Player.DirectedPosition(p0.head().position(), newDir)); + return GameState.pivotPath(Player.DirectedPosition.moving(p0.head()), newDir); + + return Player.DirectedPosition.moving(new Player.DirectedPosition(p0.head().position(), newDir)); } /** @@ -325,12 +328,13 @@ public final class GameState { */ private static boolean isColliding(Sq path, Board board1, Set bombedCells1) { SubCell nextPos = path.tail().head().position(); - if (!board1.blockAt(nextPos.containingCell()).canHostPlayer()) + SubCell nextCentralPos = GameState.nextCentralPosition(path.tail()); + + if (!board1.blockAt(nextCentralPos.containingCell()).canHostPlayer()) return true; - SubCell nextCentralPos = GameState.nextCentralPosition(path.tail()); if (bombedCells1.contains(nextCentralPos.containingCell())) - if (nextPos.distanceTo(nextCentralPos) <= Board.BOMB_BLOCKING_DISTANCE) + if (nextPos.distanceTo(nextCentralPos) <= Board.BOMB_BLOCKING_DISTANCE + 1) return true; return false; -- cgit v1.2.3