added variable camera speed
This commit is contained in:
parent
050344648d
commit
6f2f2fae1f
@ -63,7 +63,7 @@ public class InteractionCell extends Cell {
|
||||
window.getCamera().setCameraStart();
|
||||
window.getCamera().setCameraBound(false);
|
||||
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();
|
||||
}
|
||||
else if (data.contains("<dialog>")) {
|
||||
|
||||
@ -8,10 +8,11 @@ public class Camera {
|
||||
private boolean isBound;
|
||||
private int endX;
|
||||
private int endY;
|
||||
private int speed;
|
||||
private double time;
|
||||
private int startX;
|
||||
private int startY;
|
||||
private boolean isReturning;
|
||||
private static int count = 0;
|
||||
|
||||
public Camera(WindowOfFreeMove window, WindowOfFreeMove.Canvas canvas) {
|
||||
this.window = window;
|
||||
@ -78,14 +79,28 @@ public class Camera {
|
||||
if (coordX != endX || coordY != endY) {
|
||||
int distanceX = endX - startX;
|
||||
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;
|
||||
isReturning = false;
|
||||
return;
|
||||
}
|
||||
int stepX = distanceX * speed / CELL_SIZE;
|
||||
int stepY = distanceY * speed / CELL_SIZE;
|
||||
canvas.setLocation(coordX + stepX, coordY + stepY);
|
||||
// if (time >= 2) {
|
||||
if (count >= time / 2) {
|
||||
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) {
|
||||
isBound = true;
|
||||
@ -111,7 +126,7 @@ public class Camera {
|
||||
else if (CELL_SIZE * WINDOW_WIDTH - endY > CELL_SIZE * CANVAS_WIDTH) {
|
||||
endY = (-1) * (CELL_SIZE * CANVAS_HEIGHT - CELL_SIZE * WINDOW_HEIGHT);
|
||||
}
|
||||
speed = 1;
|
||||
time = 1;
|
||||
isReturning = true;
|
||||
}
|
||||
|
||||
@ -125,8 +140,8 @@ public class Camera {
|
||||
this.endY = y;
|
||||
}
|
||||
|
||||
public void setCameraSpeed(int speed) {
|
||||
this.speed = speed;
|
||||
public void setCameraTime(double time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public void setCameraBound(boolean bound) { this.isBound = bound; }
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
Roses are red<br/>violets are blue
|
||||
<cameraFree> -240 -40 1
|
||||
<cameraFree> -240 -40 4
|
||||
unexpected "{"<br/>on line 32
|
||||
<end>
|
||||
Loading…
x
Reference in New Issue
Block a user