mirror of
https://github.com/Stefan-5422/School-Programming-Projekt-022022.git
synced 2026-09-04 00:46:01 +02:00
Center hub on start and when pressing the home key
This commit is contained in:
@@ -36,8 +36,8 @@ public class PlayerManager {
|
|||||||
scene.heightProperty().addListener((e) -> redrawChunks());
|
scene.heightProperty().addListener((e) -> redrawChunks());
|
||||||
|
|
||||||
world.setOnMouseClicked(this::processClick);
|
world.setOnMouseClicked(this::processClick);
|
||||||
world.setTranslateX(GameManager.START_POSITION.x);
|
world.setTranslateX(GameManager.START_POSITION.x + world.getScene().getWidth() / 2 + 100);
|
||||||
world.setTranslateY(GameManager.START_POSITION.y);
|
world.setTranslateY(GameManager.START_POSITION.y + world.getScene().getHeight() / 2 + 100);
|
||||||
world.setOnMouseMoved((mouse) -> currentMousePosition = new Coordinate((int) mouse.getX(), (int) mouse.getY()));
|
world.setOnMouseMoved((mouse) -> currentMousePosition = new Coordinate((int) mouse.getX(), (int) mouse.getY()));
|
||||||
|
|
||||||
redrawChunks();
|
redrawChunks();
|
||||||
@@ -83,8 +83,8 @@ public class PlayerManager {
|
|||||||
|
|
||||||
private void processKeyRelease(KeyEvent key) {
|
private void processKeyRelease(KeyEvent key) {
|
||||||
if (HOME_KEY.match(key)) {
|
if (HOME_KEY.match(key)) {
|
||||||
world.setTranslateX(GameManager.START_POSITION.x);
|
world.setTranslateX(GameManager.START_POSITION.x + world.getScene().getWidth() / 2 + 100);
|
||||||
world.setTranslateY(GameManager.START_POSITION.y);
|
world.setTranslateY(GameManager.START_POSITION.y + world.getScene().getHeight() / 2 + 100);
|
||||||
redrawChunks();
|
redrawChunks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ public class PlayerManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Size preferredAmountOfChunks = getPreferredAmountOfChunks();
|
Size preferredAmountOfChunks = getPreferredAmountOfChunks();
|
||||||
Coordinate chunkPosition = Coordinate.sceneToChunkCoordinate(new Coordinate(((int) world.getTranslateX()), ((int) world.getTranslateY())));
|
Coordinate chunkPosition = Coordinate.sceneToChunkCoordinate(new Coordinate((int) world.getTranslateX() + 100, (int) world.getTranslateY() + 100));
|
||||||
|
|
||||||
if (chunkPosition.x < chunkPos.x) {
|
if (chunkPosition.x < chunkPos.x) {
|
||||||
for (int i = 0; i < preferredAmountOfChunks.y; i++) {
|
for (int i = 0; i < preferredAmountOfChunks.y; i++) {
|
||||||
@@ -146,7 +146,7 @@ public class PlayerManager {
|
|||||||
|
|
||||||
private void redrawChunks() {
|
private void redrawChunks() {
|
||||||
Size preferredAmountOfChunks = getPreferredAmountOfChunks();
|
Size preferredAmountOfChunks = getPreferredAmountOfChunks();
|
||||||
Coordinate chunkPosition = Coordinate.sceneToChunkCoordinate(new Coordinate(((int) world.getTranslateX()), ((int) world.getTranslateY())));
|
Coordinate chunkPosition = Coordinate.sceneToChunkCoordinate(new Coordinate((int) world.getTranslateX() + 100, (int) world.getTranslateY() + 100));
|
||||||
|
|
||||||
world.unloadAllChunks();
|
world.unloadAllChunks();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user