diff --git a/src/main/java/seng302/visualiser/GameClient.java b/src/main/java/seng302/visualiser/GameClient.java index cf4590ca..6246eef3 100644 --- a/src/main/java/seng302/visualiser/GameClient.java +++ b/src/main/java/seng302/visualiser/GameClient.java @@ -215,6 +215,7 @@ public class GameClient { * Updates the position of a boat. Boat and position are given in the provided data. */ private void updatePosition(PositionUpdateData positionData) { + raceView.getGameView().trackBoat(); if (positionData.getType() == DeviceType.YACHT_TYPE) { if (allXMLReceived() && allBoatsMap.containsKey(positionData.getDeviceId())) { Yacht yacht = allBoatsMap.get(positionData.getDeviceId()); @@ -306,11 +307,9 @@ public class GameClient { //TODO Allow a zoom in and zoom out methods case Z: // zoom in raceView.getGameView().zoomIn(); - System.out.println("Zoom in"); break; case X: // zoom out raceView.getGameView().zoomOut(); - System.out.println("Zoom out"); break; } } diff --git a/src/main/java/seng302/visualiser/GameView.java b/src/main/java/seng302/visualiser/GameView.java index 1f0a6ceb..f984186a 100644 --- a/src/main/java/seng302/visualiser/GameView.java +++ b/src/main/java/seng302/visualiser/GameView.java @@ -88,15 +88,15 @@ public class GameView extends Pane { double scaleFactor = 1; public void zoomOut() { - scaleFactor = 0.95; - this.setScaleX(this.getScaleX() * scaleFactor); - this.setScaleY(this.getScaleY() * scaleFactor); + scaleFactor = 0.05; + this.setScaleX(this.getScaleX() - scaleFactor); + this.setScaleY(this.getScaleY() - scaleFactor); } public void zoomIn() { - scaleFactor = 1.05; - this.setScaleX(this.getScaleX() * scaleFactor); - this.setScaleY(this.getScaleY() * scaleFactor); + scaleFactor = 0.05; + this.setScaleX(this.getScaleX() + scaleFactor); + this.setScaleY(this.getScaleY() + scaleFactor); } private enum ScaleDirection { @@ -104,6 +104,25 @@ public class GameView extends Pane { VERTICAL } + public void trackBoat() { + if (this.getScaleX() > 1) { + double x = boatObjects.get(playerYacht).getBoatLayoutX(); + double y = boatObjects.get(playerYacht).getBoatLayoutY(); +// System.out.println("x = " + x); +// System.out.println("y = " + y); +// this.setRotate(-playerYacht.getHeading()); + Point2D displacementX = findScaledXY(maxLonPoint); + Point2D displacementY = findScaledXY(maxLatPoint); + this.setLayoutX(-x + 250 + canvasWidth/2); + this.setLayoutY(-y + canvasHeight/2); + } else { + this.setLayoutX(0); + this.setLayoutY(0); + } + System.out.println("boatObjects = " + boatObjects.get(playerYacht).getBoatLayoutX()); + System.out.println("boatObjects = " + boatObjects.get(playerYacht).getBoatLayoutY()); + } + public GameView () { gameObjects = this.getChildren(); // create image view for map, bind panel size to image