added variable camera speed

This commit is contained in:
musilto9 2020-03-25 12:23:50 +01:00
parent 050344648d
commit 6f2f2fae1f
3 changed files with 25 additions and 10 deletions

View File

@ -63,7 +63,7 @@ public class InteractionCell extends Cell {
window.getCamera().setCameraStart(); window.getCamera().setCameraStart();
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().setCameraSpeed(Integer.parseInt(cameraInfo[3])); window.getCamera().setCameraTime(Double.parseDouble(cameraInfo[3]));
readNextLine(); readNextLine();
} }
else if (data.contains("<dialog>")) { else if (data.contains("<dialog>")) {

View File

@ -8,10 +8,11 @@ public class Camera {
private boolean isBound; private boolean isBound;
private int endX; private int endX;
private int endY; private int endY;
private int speed; private double time;
private int startX; private int startX;
private int startY; private int startY;
private boolean isReturning; private boolean isReturning;
private static int count = 0;
public Camera(WindowOfFreeMove window, WindowOfFreeMove.Canvas canvas) { public Camera(WindowOfFreeMove window, WindowOfFreeMove.Canvas canvas) {
this.window = window; this.window = window;
@ -78,14 +79,28 @@ public class Camera {
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;
if (Math.abs(distanceX) < CELL_SIZE && Math.abs(distanceY) < CELL_SIZE) { if (Math.abs(distanceX) < CELL_SIZE && Math.abs(distanceY) < CELL_SIZE) {
isBound = true; isBound = true;
isReturning = false; isReturning = false;
return; return;
} }
int stepX = distanceX * speed / CELL_SIZE; // if (time >= 2) {
int stepY = distanceY * speed / CELL_SIZE; if (count >= time / 2) {
canvas.setLocation(coordX + stepX, coordY + stepY); int stepX = (int) (distanceX / CELL_SIZE / (time / 2));
int stepY = (int) (distanceY / CELL_SIZE / (time / 2));
canvas.setLocation(coordX + stepX, coordY + stepY);
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++;
} }
if (coordX == endX && coordY == endY && isReturning) { if (coordX == endX && coordY == endY && isReturning) {
isBound = true; isBound = true;
@ -111,7 +126,7 @@ public class Camera {
else if (CELL_SIZE * WINDOW_WIDTH - endY > CELL_SIZE * CANVAS_WIDTH) { else if (CELL_SIZE * WINDOW_WIDTH - endY > CELL_SIZE * CANVAS_WIDTH) {
endY = (-1) * (CELL_SIZE * CANVAS_HEIGHT - CELL_SIZE * WINDOW_HEIGHT); endY = (-1) * (CELL_SIZE * CANVAS_HEIGHT - CELL_SIZE * WINDOW_HEIGHT);
} }
speed = 1; time = 1;
isReturning = true; isReturning = true;
} }
@ -125,8 +140,8 @@ public class Camera {
this.endY = y; this.endY = y;
} }
public void setCameraSpeed(int speed) { public void setCameraTime(double time) {
this.speed = speed; this.time = time;
} }
public void setCameraBound(boolean bound) { this.isBound = bound; } public void setCameraBound(boolean bound) { this.isBound = bound; }

View File

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