From 6f2f2fae1fe18f2f9e4500dfd460713936683057 Mon Sep 17 00:00:00 2001 From: musilto9 Date: Wed, 25 Mar 2020 12:23:50 +0100 Subject: [PATCH] added variable camera speed --- .../gameOfProd/Cells/InteractionCell.java | 2 +- .../ruscz/game/gameOfProd/Windows/Camera.java | 31 ++++++++++++++----- src/main/resources/roses-are-red.txt | 2 +- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java index a979b81..90acffb 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java @@ -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("")) { diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/Camera.java b/src/main/java/ruscz/game/gameOfProd/Windows/Camera.java index 2b88a24..2c099f4 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/Camera.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/Camera.java @@ -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; } diff --git a/src/main/resources/roses-are-red.txt b/src/main/resources/roses-are-red.txt index b42d635..9bf394a 100644 --- a/src/main/resources/roses-are-red.txt +++ b/src/main/resources/roses-are-red.txt @@ -1,4 +1,4 @@ Roses are red
violets are blue - -240 -40 1 + -240 -40 4 unexpected "{"
on line 32 \ No newline at end of file