diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Person.java b/src/main/java/ruscz/game/gameOfProd/Cells/Person.java index 18f893b..58bac25 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/Person.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/Person.java @@ -232,6 +232,10 @@ public class Person extends Cell { this.size = size; } + public int getSize() { return size; } + + public int getDirectionMoveLast() {return directionMoveLast; } + public static void setInEvent(boolean isInEvent) { Person.isInEvent = isInEvent; } diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java index fd3bded..d805db0 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java @@ -19,10 +19,10 @@ import java.util.LinkedList; public class WindowOfFreeMove extends JFrame { public static final int CELL_SIZE = 40; - public static final int CANVAS_WIDTH = 10; - public static final int CANVAS_HEIGHT = 10; - public static final int WINDOW_WIDTH = 5; - public static final int WINDOW_HEIGHT = 5; + public static final int CANVAS_WIDTH = 20; + public static final int CANVAS_HEIGHT = 20; + public static final int WINDOW_WIDTH = 10; + public static final int WINDOW_HEIGHT = 10; private static boolean canPersonMove; private static int nextMove; @@ -79,7 +79,7 @@ public class WindowOfFreeMove extends JFrame { JLayeredPane lp = getLayeredPane(); canvas = new Canvas(); - canvas.setBackground(Color.white); + canvas.setBackground(Color.black); canvas.setPreferredSize(new Dimension( CELL_SIZE * CANVAS_WIDTH, CELL_SIZE * CANVAS_HEIGHT)); @@ -190,7 +190,7 @@ public class WindowOfFreeMove extends JFrame { setMap(m5); - canvas.setLocation((-1) * CELL_SIZE * (map.getActualMap().getPerson().getX() - WINDOW_WIDTH / 2), (-1) * CELL_SIZE * (map.getActualMap().getPerson().getY() - WINDOW_HEIGHT / 2)); + moveCamera(); map.createMap(); isReadyToPaint = true; @@ -200,7 +200,7 @@ public class WindowOfFreeMove extends JFrame { @Override public void actionPerformed(ActionEvent actionEvent) { map.getActualMap().getPerson().move(); - canvas.setLocation((-1) * CELL_SIZE * (map.getActualMap().getPerson().getX() - WINDOW_WIDTH / 2), (-1) * CELL_SIZE * (map.getActualMap().getPerson().getY() - WINDOW_HEIGHT / 2)); + moveCamera(); canvas.repaint(); } }); @@ -234,6 +234,49 @@ public class WindowOfFreeMove extends JFrame { } } + public void moveCamera() { + int cameraOffsetX = (-1) * CELL_SIZE * (map.getActualMap().getPerson().getX() - WINDOW_WIDTH / 2); + int cameraOffsetY = (-1) * CELL_SIZE * (map.getActualMap().getPerson().getY() - WINDOW_HEIGHT / 2); + int direction = map.getActualMap().getPerson().getDirectionMoveLast(); + int size = -map.getActualMap().getPerson().getSize(); + int Ysize = 0; + int Xsize = 0; + switch (direction) { + case WindowOfFreeMove.KEY_LEFT: + Xsize = size; + break; + case WindowOfFreeMove.KEY_RIGHT: + Xsize -= size; + break; + case WindowOfFreeMove.KEY_UP: + Ysize = size; + break; + case WindowOfFreeMove.KEY_DOWN: + Ysize -= size; + break; + } + if (!map.getActualMap().getPerson().getIsMoving()) { + Xsize = 0; + Ysize = 0; + } + if (cameraOffsetX + Xsize >= 0 || cameraOffsetX > 0) { + cameraOffsetX = 0; + Xsize = 0; + } + else if (CELL_SIZE * WINDOW_WIDTH - (cameraOffsetX + Xsize) >= CELL_SIZE * CANVAS_WIDTH || CELL_SIZE * WINDOW_WIDTH - cameraOffsetX > CELL_SIZE * CANVAS_WIDTH) { + cameraOffsetX = (-1) * (CELL_SIZE * CANVAS_WIDTH - CELL_SIZE * WINDOW_WIDTH); + Xsize = 0; + } + if (cameraOffsetY + Ysize >= 0 || cameraOffsetX > 0) { + cameraOffsetY = 0; + Ysize = 0; + } + else if (CELL_SIZE * WINDOW_HEIGHT - (cameraOffsetY + Ysize) >= CELL_SIZE * CANVAS_HEIGHT || CELL_SIZE * WINDOW_HEIGHT - cameraOffsetY > CELL_SIZE * CANVAS_HEIGHT) { + cameraOffsetY = (-1) * (CELL_SIZE * CANVAS_HEIGHT - CELL_SIZE * WINDOW_HEIGHT); + Ysize = 0; + } + canvas.setLocation(cameraOffsetX + Xsize, cameraOffsetY + Ysize); + } protected static void sleep(long tm) { try { diff --git a/src/main/resources/maps/m2-tileset.txt b/src/main/resources/maps/m2-tileset.txt index f2397a7..aaeefff 100644 --- a/src/main/resources/maps/m2-tileset.txt +++ b/src/main/resources/maps/m2-tileset.txt @@ -1,12 +1,22 @@ A2_Ground.png 512 384 32 D_OutDoor.png 512 512 32 -1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 -1 1 82 94 1 1 82 94 1 1 -1 1 83 95 1 1 83 95 1 1 -1 1 1 1 1 1 1 1 1 1 -1 1 153 1 1 1 1 153 1 1 -1 1 1 153 153 153 153 1 1 1 -1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +1 1 82 94 1 1 82 94 1 1 1 1 82 94 1 1 82 94 1 1 +1 1 83 95 1 1 83 95 1 1 1 1 83 95 1 1 83 95 1 1 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +1 1 153 1 1 1 1 153 1 1 1 1 1 1 1 1 1 1 1 1 +1 1 1 153 153 153 153 1 1 1 1 1 1 153 153 153 153 1 1 1 +1 1 1 1 1 1 1 1 1 1 1 1 153 1 1 1 1 153 1 1 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +1 1 82 94 1 1 82 94 1 1 1 1 82 94 1 1 82 94 1 1 +1 1 83 95 1 1 83 95 1 1 1 1 83 95 1 1 83 95 1 1 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 153 1 1 1 1 153 1 1 1 1 1 1 1 +1 1 1 153 153 153 153 1 1 1 1 1 1 153 153 153 153 1 1 1 +1 1 153 1 1 1 1 1 1 1 1 1 1 1 1 1 1 153 1 1 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1