diff options
author | Pacien TRAN-GIRARD | 2016-04-10 17:21:43 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2016-04-10 17:21:43 +0200 |
commit | ccb2248d468852e5f7f88dcbed10fd00efa4b3d2 (patch) | |
tree | 9519bbfc0f455c793b064c2d4c3ac47b9183eec6 | |
parent | 32d00b913c713856f52e932dc885a44ef44586d4 (diff) | |
download | xblast-ccb2248d468852e5f7f88dcbed10fd00efa4b3d2.tar.gz |
Fix collision calculation for walls and stopped player self starting path
-rw-r--r-- | src/ch/epfl/xblast/server/GameState.java | 18 |
1 files changed, 11 insertions, 7 deletions
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 { | |||
241 | */ | 241 | */ |
242 | private static Sq<Player.DirectedPosition> nextPath(Player p0, Direction requestedDir) { | 242 | private static Sq<Player.DirectedPosition> nextPath(Player p0, Direction requestedDir) { |
243 | return GameState.newPath( | 243 | return GameState.newPath( |
244 | Player.DirectedPosition.moving(p0.directedPositions().head()), | 244 | p0.directedPositions(), |
245 | GameState.nextDirection(p0, requestedDir)); | 245 | GameState.nextDirection(p0, requestedDir)); |
246 | } | 246 | } |
247 | 247 | ||
@@ -253,10 +253,13 @@ public final class GameState { | |||
253 | * @return the new path | 253 | * @return the new path |
254 | */ | 254 | */ |
255 | private static Sq<Player.DirectedPosition> newPath(Sq<Player.DirectedPosition> p0, Direction newDir) { | 255 | private static Sq<Player.DirectedPosition> newPath(Sq<Player.DirectedPosition> p0, Direction newDir) { |
256 | if (newDir == p0.head().direction()) | ||
257 | return p0; | ||
258 | |||
256 | if (p0.head().direction().isPerpendicularTo(newDir)) | 259 | if (p0.head().direction().isPerpendicularTo(newDir)) |
257 | return GameState.pivotPath(p0, newDir); | 260 | return GameState.pivotPath(Player.DirectedPosition.moving(p0.head()), newDir); |
258 | else | 261 | |
259 | return Player.DirectedPosition.moving(new Player.DirectedPosition(p0.head().position(), newDir)); | 262 | return Player.DirectedPosition.moving(new Player.DirectedPosition(p0.head().position(), newDir)); |
260 | } | 263 | } |
261 | 264 | ||
262 | /** | 265 | /** |
@@ -325,12 +328,13 @@ public final class GameState { | |||
325 | */ | 328 | */ |
326 | private static boolean isColliding(Sq<Player.DirectedPosition> path, Board board1, Set<Cell> bombedCells1) { | 329 | private static boolean isColliding(Sq<Player.DirectedPosition> path, Board board1, Set<Cell> bombedCells1) { |
327 | SubCell nextPos = path.tail().head().position(); | 330 | SubCell nextPos = path.tail().head().position(); |
328 | if (!board1.blockAt(nextPos.containingCell()).canHostPlayer()) | 331 | SubCell nextCentralPos = GameState.nextCentralPosition(path.tail()); |
332 | |||
333 | if (!board1.blockAt(nextCentralPos.containingCell()).canHostPlayer()) | ||
329 | return true; | 334 | return true; |
330 | 335 | ||
331 | SubCell nextCentralPos = GameState.nextCentralPosition(path.tail()); | ||
332 | if (bombedCells1.contains(nextCentralPos.containingCell())) | 336 | if (bombedCells1.contains(nextCentralPos.containingCell())) |
333 | if (nextPos.distanceTo(nextCentralPos) <= Board.BOMB_BLOCKING_DISTANCE) | 337 | if (nextPos.distanceTo(nextCentralPos) <= Board.BOMB_BLOCKING_DISTANCE + 1) |
334 | return true; | 338 | return true; |
335 | 339 | ||
336 | return false; | 340 | return false; |