diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java index 16fab67..9a97a85 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java @@ -4,6 +4,7 @@ import ruscz.game.gameOfProd.Dialog.Dialog; import ruscz.game.gameOfProd.Image.ImageCell; import ruscz.game.gameOfProd.Image.ImageDialog; import ruscz.game.gameOfProd.Map.Map; +import ruscz.game.gameOfProd.Map.MapPainter; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import java.awt.*; @@ -16,12 +17,14 @@ public class InteractionCell extends Cell { private ruscz.game.gameOfProd.Dialog.Dialog dialog; private Scanner scanner; private ImageCell imageCell; + private WindowOfFreeMove window; - public InteractionCell(int x, int y, String message, Dialog dialog, ImageCell imageCell) { + public InteractionCell(int x, int y, String message, Dialog dialog, ImageCell imageCell, WindowOfFreeMove window) { super(x, y, WindowOfFreeMove.CELL_SIZE, Color.ORANGE); this.message = message; this.dialog = dialog; this.imageCell = imageCell; + this.window = window; } public void startEvent() { @@ -43,13 +46,22 @@ public class InteractionCell extends Cell { public void readNextLine() { if (scanner.hasNextLine() && !dialog.getTimerIsRunning()) { String data = scanner.nextLine(); - if (data.equals("")) + if (data.equals("")) { + window.getMapPainter().setCameraBound(true); endEvent(); + } else if (data.contains("")) { String[] imageName = data.split(" "); dialog.setImageDialog(new ImageDialog(imageName[1])); readNextLine(); } + else if (data.contains("")) { + String[] cameraInfo = data.split(" "); + window.getMapPainter().setCameraStart(); + window.getMapPainter().setCameraBound(false); + window.getMapPainter().setCameraEnd(Integer.parseInt(cameraInfo[1]), Integer.parseInt(cameraInfo[2])); + window.getMapPainter().setCameraSpeed(Integer.parseInt(cameraInfo[3])); + } else { if (data.contains("
")) data = "" + data + ""; diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java index be30abd..95719d6 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/TriggerCell.java @@ -9,8 +9,8 @@ import java.awt.*; public class TriggerCell extends InteractionCell { private boolean isActive; - public TriggerCell(int x, int y, String message, Dialog dialog, ImageCell imageCell) { - super(x, y, message, dialog, imageCell); + public TriggerCell(int x, int y, String message, Dialog dialog, ImageCell imageCell, WindowOfFreeMove window) { + super(x, y, message, dialog, imageCell, window); this.isActive = true; } diff --git a/src/main/java/ruscz/game/gameOfProd/Map/Map.java b/src/main/java/ruscz/game/gameOfProd/Map/Map.java index faeb070..a9193de 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/Map.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/Map.java @@ -141,11 +141,11 @@ public class Map { } else if (line[x].contains("INTER")) { ImageCell imageCell = new ImageCell(); String[] event = line[x].split(","); - map.addInteractionEvent(new InteractionCell(x, y, event[1], new Dialog(window.getDialogBar()), map.getImageCell())); + map.addInteractionEvent(new InteractionCell(x, y, event[1], new Dialog(window.getDialogBar()), map.getImageCell(), window)); } else if (line[x].contains("TRIGGER")) { ImageCell imageCell = new ImageCell(); String[] trigger = line[x].split(","); - map.addInteractionEvent(new TriggerCell(x, y, trigger[1], new Dialog(window.getDialogBar()), map.getImageCell())); + map.addInteractionEvent(new TriggerCell(x, y, trigger[1], new Dialog(window.getDialogBar()), map.getImageCell(), window)); } else if (line[x].equals("SPAWN")) { map.setSpawnPoint(x, y); } diff --git a/src/main/java/ruscz/game/gameOfProd/Map/MapPainter.java b/src/main/java/ruscz/game/gameOfProd/Map/MapPainter.java index 2af38d2..5d97b03 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/MapPainter.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/MapPainter.java @@ -14,10 +14,17 @@ public class MapPainter { private WindowOfFreeMove.Canvas canvas; private LinkedList maps; private Map actualMap; + private boolean isCameraBound; + private int cameraEndX; + private int cameraEndY; + private int cameraSpeed; + private int cameraStartX; + private int cameraStartY; public MapPainter(LinkedList maps, WindowOfFreeMove.Canvas canvas) { this.canvas = canvas; this.maps = maps; + this.isCameraBound = true; } public void setMap(Map map) { @@ -90,6 +97,15 @@ public class MapPainter { } public void moveCamera() { + if (isCameraBound) { + moveBoundCamera(); + } + else { + moveFreeCamera(); + } + } + + public void moveBoundCamera() { int cameraOffsetX = (-1) * CELL_SIZE * (getActualMap().getPerson().getX() - WINDOW_WIDTH / 2); int cameraOffsetY = (-1) * CELL_SIZE * (getActualMap().getPerson().getY() - WINDOW_HEIGHT / 2); int direction = getActualMap().getPerson().getDirectionMoveLast(); @@ -133,7 +149,39 @@ public class MapPainter { canvas.setLocation(cameraOffsetX + Xsize, cameraOffsetY + Ysize); } + public void moveFreeCamera() { + int coordX = (int) (canvas.getLocation().getX()); + int coordY = (int) (canvas.getLocation().getY()); + if (coordX != cameraEndX || coordY != cameraEndY) { + int distanceX = cameraEndX - cameraStartX; + int distanceY = cameraEndY - cameraStartY; + 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); + } + } + public void repaintCanvas() { canvas.repaint(); } + + public void setCameraStart() { + this.cameraStartX = (int) (canvas.getLocation().getX()); + this.cameraStartY = (int) (canvas.getLocation().getY()); + } + + public void setCameraEnd(int x, int y) { + this.cameraEndX = x; + this.cameraEndY = y; + } + + public void setCameraSpeed(int speed) { + this.cameraSpeed = speed; + } + + public void setCameraBound(boolean bound) { this.isCameraBound = bound; } } diff --git a/src/main/resources/roses-are-red.txt b/src/main/resources/roses-are-red.txt index f2f1d83..2f52d7f 100644 --- a/src/main/resources/roses-are-red.txt +++ b/src/main/resources/roses-are-red.txt @@ -1,3 +1,4 @@ Roses are red
violets are blue + -40 0 1 unexpected "{"
on line 32 \ No newline at end of file