bruteforce-fixed free camera

This commit is contained in:
musilto9 2020-03-26 22:13:31 +01:00
parent b5064f6484
commit 22bee3b9b4
8 changed files with 76 additions and 36 deletions

View File

@ -64,6 +64,7 @@ public class InteractionCell extends Cell {
window.getCamera().setCameraBound(false); window.getCamera().setCameraBound(false);
window.getCamera().setCameraEnd(Integer.parseInt(cameraInfo[1]), Integer.parseInt(cameraInfo[2])); window.getCamera().setCameraEnd(Integer.parseInt(cameraInfo[1]), Integer.parseInt(cameraInfo[2]));
window.getCamera().setCameraTime(Double.parseDouble(cameraInfo[3])); window.getCamera().setCameraTime(Double.parseDouble(cameraInfo[3]));
window.getCamera().setCameraStopped(false);
readNextLine(); readNextLine();
} }
else if (data.contains("<dialog>")) { else if (data.contains("<dialog>")) {
@ -105,6 +106,7 @@ public class InteractionCell extends Cell {
dialog.setImageDialog(null); dialog.setImageDialog(null);
} }
if (!window.getCamera().getCameraBound()) { if (!window.getCamera().getCameraBound()) {
window.getCamera().setCameraStopped(false);
window.getCamera().returnFreeCamera(); window.getCamera().returnFreeCamera();
} }
else { else {

View File

@ -23,6 +23,7 @@ public class Map {
private LinkedList<Npc> npcs; private LinkedList<Npc> npcs;
private int idExit; private int idExit;
private ImageCell imageCell; private ImageCell imageCell;
private int[] canvasSize;
private static Scanner scanner; private static Scanner scanner;
@ -77,8 +78,8 @@ public class Map {
mapArray[i][0] = type; mapArray[i][0] = type;
mapArray[i][mapArray[0].length - 1] = type; mapArray[i][mapArray[0].length - 1] = type;
} }
person = new Person(this); person = new Person(this);
canvasSize = new int[2];
} }
public Map(TypeOfCell[][] mapArray) { public Map(TypeOfCell[][] mapArray) {
@ -91,6 +92,7 @@ public class Map {
npcs = new LinkedList<>(); npcs = new LinkedList<>();
this.mapArray = mapArray; this.mapArray = mapArray;
person = new Person(this); person = new Person(this);
canvasSize = new int[2];
} }
public static Map findMapByName(String nameOfMap, WindowOfFreeMove window) { public static Map findMapByName(String nameOfMap, WindowOfFreeMove window) {
@ -114,6 +116,8 @@ public class Map {
map.npcs = new LinkedList<>(); map.npcs = new LinkedList<>();
map.getImageCell().readMapFile(name + "-tileset"); map.getImageCell().readMapFile(name + "-tileset");
LinkedList<String[]> listOfMoveToCells = new LinkedList<>(); LinkedList<String[]> listOfMoveToCells = new LinkedList<>();
map.canvasSize[0] = Integer.parseInt(size[0]);
map.canvasSize[1] = Integer.parseInt(size[1]);
int y = 0; int y = 0;
while (scanner.hasNextLine()) { while (scanner.hasNextLine()) {
loadMap(map, size, y, window); loadMap(map, size, y, window);
@ -244,6 +248,8 @@ public class Map {
return mapArray; return mapArray;
} }
public int[] getCanvasSize() { return canvasSize; }
public boolean isBusyCell(int x, int y) { public boolean isBusyCell(int x, int y) {
for (Block cell : block) { for (Block cell : block) {

View File

@ -23,9 +23,13 @@ public class MapPainter {
public void setMap(Map map) { public void setMap(Map map) {
if (maps.contains(map)) { if (maps.contains(map)) {
actualMap = map; actualMap = map;
WindowOfFreeMove.setCanvasSize(map.getCanvasSize());
resizeCanvas(map.getCanvasSize());
} else { } else {
maps.add(map); maps.add(map);
actualMap = map; actualMap = map;
WindowOfFreeMove.setCanvasSize(map.getCanvasSize());
resizeCanvas(map.getCanvasSize());
} }
} }
@ -92,4 +96,11 @@ public class MapPainter {
public void repaintCanvas() { public void repaintCanvas() {
canvas.repaint(); canvas.repaint();
} }
public void resizeCanvas(int[] size) {
canvas.setPreferredSize(new Dimension(
CELL_SIZE * size[0],
CELL_SIZE * size[1]));
canvas.setBounds(0, 0, CELL_SIZE * size[0], CELL_SIZE * size[1]);
}
} }

View File

@ -13,6 +13,7 @@ public class Camera {
private int startY; private int startY;
private boolean isReturning; private boolean isReturning;
private static int count = 0; private static int count = 0;
private boolean isStopped;
public Camera(WindowOfFreeMove window, WindowOfFreeMove.Canvas canvas) { public Camera(WindowOfFreeMove window, WindowOfFreeMove.Canvas canvas) {
this.window = window; this.window = window;
@ -25,7 +26,8 @@ public class Camera {
moveBoundCamera(); moveBoundCamera();
} }
else { else {
moveFreeCamera(); if (!isStopped)
moveFreeCamera();
} }
} }
@ -76,6 +78,22 @@ public class Camera {
public void moveFreeCamera() { public void moveFreeCamera() {
int coordX = (int) (canvas.getLocation().getX()); int coordX = (int) (canvas.getLocation().getX());
int coordY = (int) (canvas.getLocation().getY()); int coordY = (int) (canvas.getLocation().getY());
if (coordX > 0) {
endX = 0;
if (isReturning) boundCamera();
}
else if (CELL_SIZE * WINDOW_WIDTH - coordX + 8 >= CELL_SIZE * CANVAS_WIDTH) {
if (isReturning) boundCamera();
else isStopped = true;
}
if (coordY > 0) {
if (isReturning) boundCamera();
else isStopped = true;
}
else if (CELL_SIZE * WINDOW_WIDTH - coordY >= CELL_SIZE * CANVAS_WIDTH) {
if (isReturning) boundCamera();
else isStopped = true;
}
if (coordX != endX || coordY != endY) { if (coordX != endX || coordY != endY) {
int distanceX = endX - startX; int distanceX = endX - startX;
int distanceY = endY - startY; int distanceY = endY - startY;
@ -84,30 +102,15 @@ public class Camera {
isReturning = false; isReturning = false;
return; return;
} }
// if (time >= 2) { if (count >= time / 2) {
if (count >= time / 2) { int stepX = (int) (distanceX / CELL_SIZE / (time / 2));
int stepX = (int) (distanceX / CELL_SIZE / (time / 2)); int stepY = (int) (distanceY / CELL_SIZE / (time / 2));
int stepY = (int) (distanceY / CELL_SIZE / (time / 2)); canvas.setLocation(coordX + stepX, coordY + stepY);
canvas.setLocation(coordX + stepX, coordY + stepY); count = 0;
count = 0; }
}
// }
// else {
// if (count >= time) {
// int stepX = distanceX / CELL_SIZE;
// int stepY = distanceY / CELL_SIZE;
// canvas.setLocation(coordX + stepX, coordY + stepY);
// count = 0;
// }
// }
count++; count++;
} }
if (coordX == endX && coordY == endY && isReturning) { if (coordX == endX && coordY == endY && isReturning) boundCamera();
isBound = true;
isReturning = false;
window.setCanPersonMove(true);
window.getMapPainter().getActualMap().getPerson().setInEvent(false);
}
} }
public void returnFreeCamera() { public void returnFreeCamera() {
@ -130,6 +133,17 @@ public class Camera {
isReturning = true; isReturning = true;
} }
public void stopCamera() {
}
public void boundCamera() {
isBound = true;
isReturning = false;
window.setCanPersonMove(true);
window.getMapPainter().getActualMap().getPerson().setInEvent(false);
}
public void setCameraStart() { public void setCameraStart() {
this.startX = (int) (canvas.getLocation().getX()); this.startX = (int) (canvas.getLocation().getX());
this.startY = (int) (canvas.getLocation().getY()); this.startY = (int) (canvas.getLocation().getY());
@ -146,5 +160,7 @@ public class Camera {
public void setCameraBound(boolean bound) { this.isBound = bound; } public void setCameraBound(boolean bound) { this.isBound = bound; }
public boolean getCameraBound() {return isBound; } public boolean getCameraBound() { return isBound; }
public void setCameraStopped(boolean stopped) { isStopped = stopped; }
} }

View File

@ -15,10 +15,10 @@ import java.util.LinkedList;
public class WindowOfFreeMove extends JFrame { public class WindowOfFreeMove extends JFrame {
public static final int CELL_SIZE = 40; public static final int CELL_SIZE = 40;
public static final int CANVAS_WIDTH = 36; public static int CANVAS_WIDTH = 50;
public static final int CANVAS_HEIGHT = 36; public static int CANVAS_HEIGHT = 50;
public static final int WINDOW_WIDTH = 11; public static final int WINDOW_WIDTH = 9;
public static final int WINDOW_HEIGHT = 11; public static final int WINDOW_HEIGHT = 9;
private static boolean canPersonMove; private static boolean canPersonMove;
private static int nextMove; private static int nextMove;
@ -133,7 +133,7 @@ public class WindowOfFreeMove extends JFrame {
setTitle("Ahoj"); setTitle("Ahoj");
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(EXIT_ON_CLOSE);
setBounds(0, 0, CELL_SIZE * WINDOW_WIDTH + 15, CELL_SIZE * WINDOW_HEIGHT + 35); setBounds(0, 0, CELL_SIZE * WINDOW_WIDTH + 16, CELL_SIZE * WINDOW_HEIGHT + 39);
setLocationRelativeTo(null); setLocationRelativeTo(null);
setResizable(false); setResizable(false);
setVisible(true); setVisible(true);
@ -145,7 +145,7 @@ public class WindowOfFreeMove extends JFrame {
int count = 0; int count = 0;
for (int i = 0; i < rec.length / 4; i++) { for (int i = 0; i < rec.length / 4; i++) {
for (int j = 0; j < rec.length / 3; j++) { for (int j = 0; j < rec.length / 3; j++) {
rec[count] = new Rectangle(40 * i, 40 * j, 40, 40); rec[count] = new Rectangle(CELL_SIZE * i, CELL_SIZE * j, CELL_SIZE, CELL_SIZE);
count++; count++;
} }
} }
@ -227,8 +227,8 @@ public class WindowOfFreeMove extends JFrame {
Graphics2D g2D = (Graphics2D) g; Graphics2D g2D = (Graphics2D) g;
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
for (int i = 0; i < CANVAS_WIDTH; i++) { for (int i = 0; i < mapPainter.getActualMap().getCanvasSize()[0]; i++) {
for (int j = 0; j < CANVAS_HEIGHT; j++) { for (int j = 0; j < mapPainter.getActualMap().getCanvasSize()[1]; j++) {
mapPainter.getActualMap().getImageCell().paintBackground(g2D, i, j); mapPainter.getActualMap().getImageCell().paintBackground(g2D, i, j);
} }
} }
@ -257,4 +257,9 @@ public class WindowOfFreeMove extends JFrame {
} }
} }
public static void setCanvasSize(int[] size) {
CANVAS_WIDTH = size[0];
CANVAS_HEIGHT = size[1];
}
} }

View File

@ -5,7 +5,7 @@ BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
BLOCK EMPTY EMPTY INTER,first-dialog EMPTY INTER,dialog-test EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY INTER,first-dialog EMPTY INTER,dialog-test EMPTY EMPTY EMPTY BLOCK
BLOCK EMPTY EMPTY EMPTY TRIGGER,roses-are-red EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
BLOCK MOVETO,5,1,m5 EMPTY MOVETO,6,1,m6 EMPTY EMPTY EMPTY EMPTY MOVETO,1,1,m2 BLOCK BLOCK MOVETO,5,1,m5 EMPTY MOVETO,6,1,m6 EMPTY EMPTY EMPTY EMPTY MOVETO,1,1,m2 BLOCK
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK

View File

@ -10,7 +10,7 @@ EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EM
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY TRIGGER,roses-are-red EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY

View File

@ -1,4 +1,4 @@
Roses are red<br/>violets are blue Roses are red<br/>violets are blue
<cameraFree> -240 -40 4 <cameraFree> -1200 -240 4
unexpected "{"<br/>on line 32 unexpected "{"<br/>on line 32
<end> <end>