diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java index 9a97a85..3eeee5b 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java @@ -12,6 +12,8 @@ import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; +import static ruscz.game.gameOfProd.Windows.WindowOfFreeMove.*; + public class InteractionCell extends Cell { private String message; private ruscz.game.gameOfProd.Dialog.Dialog dialog; @@ -28,8 +30,10 @@ public class InteractionCell extends Cell { } public void startEvent() { - if (message != null) + if (message != null) { + window.setCanPersonMove(false); readDialogFile(message); + } } public void readDialogFile(String name) { @@ -47,7 +51,6 @@ public class InteractionCell extends Cell { if (scanner.hasNextLine() && !dialog.getTimerIsRunning()) { String data = scanner.nextLine(); if (data.equals("")) { - window.getMapPainter().setCameraBound(true); endEvent(); } else if (data.contains("")) { @@ -61,6 +64,19 @@ public class InteractionCell extends Cell { window.getMapPainter().setCameraBound(false); window.getMapPainter().setCameraEnd(Integer.parseInt(cameraInfo[1]), Integer.parseInt(cameraInfo[2])); window.getMapPainter().setCameraSpeed(Integer.parseInt(cameraInfo[3])); + readNextLine(); + } + else if (data.contains("")) { + String[] dialogInfo = data.split(" "); + switch (dialogInfo[1]) { + case "show": + readNextLine(); + dialog.showText(); + break; + case "hide": + dialog.hideText(); + break; + } } else { if (data.contains("
")) @@ -80,6 +96,9 @@ public class InteractionCell extends Cell { dialog.hideText(); dialog.setImageDialog(null); } + if (!window.getMapPainter().getCameraBound()) { + window.getMapPainter().returnFreeCamera(); + } WindowOfFreeMove.setCanPersonMove(true); Person.setInEvent(false); } diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java index 95719d6..5072fd9 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java @@ -30,8 +30,4 @@ public class TriggerCell extends InteractionCell { public boolean getActive() { return isActive; } - - public void setActive(boolean isActive) { - this.isActive = isActive; - } } diff --git a/src/main/java/ruscz/game/gameOfProd/Map/MapPainter.java b/src/main/java/ruscz/game/gameOfProd/Map/MapPainter.java index 5d97b03..ddd5b41 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/MapPainter.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/MapPainter.java @@ -20,6 +20,7 @@ public class MapPainter { private int cameraSpeed; private int cameraStartX; private int cameraStartY; + private boolean isCameraReturning; public MapPainter(LinkedList maps, WindowOfFreeMove.Canvas canvas) { this.canvas = canvas; @@ -158,11 +159,30 @@ public class MapPainter { int stepX = distanceX * cameraSpeed / CELL_SIZE; int stepY = distanceY * cameraSpeed / CELL_SIZE; canvas.setLocation(coordX + stepX, coordY + stepY); -// System.out.println("start: " + cameraStartX + " " + cameraStartY + ", end: " + cameraEndX + " " + cameraEndY); - System.out.println("distanceX: " + distanceX + ", distanceY: " + distanceY); - System.out.println("speed: " + cameraSpeed); - System.out.println("stepX: " + stepX + ", stepY: " + stepY); } + if (coordX == cameraEndX && coordY == cameraEndY && isCameraReturning) { + isCameraBound = true; + } + } + + public void returnFreeCamera() { + setCameraStart(); + cameraEndX = (-1) * CELL_SIZE * (getActualMap().getPerson().getX() - WINDOW_WIDTH / 2); + cameraEndY = (-1) * CELL_SIZE * (getActualMap().getPerson().getY() - WINDOW_HEIGHT / 2); + if (cameraEndX > 0) { + cameraEndX = 0; + } + else if (CELL_SIZE * WINDOW_WIDTH - cameraEndX > CELL_SIZE * CANVAS_WIDTH) { + cameraEndX = (-1) * (CELL_SIZE * CANVAS_WIDTH - CELL_SIZE * WINDOW_WIDTH); + } + if (cameraEndY > 0) { + cameraEndY = 0; + } + else if (CELL_SIZE * WINDOW_WIDTH - cameraEndY > CELL_SIZE * CANVAS_WIDTH) { + cameraEndY = (-1) * (CELL_SIZE * CANVAS_HEIGHT - CELL_SIZE * WINDOW_HEIGHT); + } + cameraSpeed = 1; + isCameraReturning = true; } public void repaintCanvas() { @@ -184,4 +204,6 @@ public class MapPainter { } public void setCameraBound(boolean bound) { this.isCameraBound = bound; } + + public boolean getCameraBound() {return isCameraBound; } } diff --git a/src/main/resources/first-dialog.txt b/src/main/resources/first-dialog.txt index 53c3e6b..417dd38 100644 --- a/src/main/resources/first-dialog.txt +++ b/src/main/resources/first-dialog.txt @@ -1,4 +1,6 @@ Keep out ... + hide + show or enter
I'm a sign not a cop \ No newline at end of file