From b56fa5cba328bb80ac983227ec1f94048a2d2e4e Mon Sep 17 00:00:00 2001 From: Peter Galloway Date: Wed, 26 Jul 2017 22:42:37 +1200 Subject: [PATCH] refactored to make boat trails work again #fix #refactor --- .../seng302/controllers/CanvasController.java | 5 +- .../java/seng302/fxObjects/BoatGroup.java | 70 +++++++------------ 2 files changed, 26 insertions(+), 49 deletions(-) diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java index 03d42872..f30969a5 100644 --- a/src/main/java/seng302/controllers/CanvasController.java +++ b/src/main/java/seng302/controllers/CanvasController.java @@ -250,11 +250,8 @@ public class CanvasController { // some raceObjects will have multiple ID's (for instance gate marks) //checking if the current "ID" has any updates associated with it if (ClientPacketParser.boatLocations.containsKey(boatGroup.getRaceId())) { - if (boatGroup.isStopped()) { - updateBoatGroup(boatGroup); - } + updateBoatGroup(boatGroup); } - boatGroup.move(); } for (MarkGroup markGroup : markGroups) { for (Long id : markGroup.getRaceIds()) { diff --git a/src/main/java/seng302/fxObjects/BoatGroup.java b/src/main/java/seng302/fxObjects/BoatGroup.java index b83e99ba..2446f9d4 100644 --- a/src/main/java/seng302/fxObjects/BoatGroup.java +++ b/src/main/java/seng302/fxObjects/BoatGroup.java @@ -163,18 +163,33 @@ public class BoatGroup extends Group { boatPoly.getTransforms().setAll(new Rotate(rotation)); } - public void move() { - double dx = xIncrement * framesToMove; - double dy = yIncrement * framesToMove; + /** + * Sets the destination of the boat and the headng it should have once it reaches + * + * @param newXValue The X co-ordinate the boat needs to move to. + * @param newYValue The Y co-ordinate the boat needs to move to. + * @param rotation Rotation to move graphics to. + * @param timeValid the time the position values are valid for + */ + public void setDestination(double newXValue, double newYValue, double rotation, + double groundSpeed, long timeValid, double frameRate) { - distanceTravelled += Math.abs(dx) + Math.abs(dy); - moveGroupBy(xIncrement, yIncrement); - framesToMove = framesToMove - 1; + destinationSet = true; + Double dx = Math.abs(boatPoly.getLayoutX() - newXValue); + Double dy = Math.abs(boatPoly.getLayoutY() - newYValue); + moveTo(newXValue, newYValue, rotation); - if (framesToMove <= 0) { - isStopped = true; - } - if (distanceTravelled > 70 && isPlayer) { + + rotateTo(rotation); + wake.setRotation(rotation, groundSpeed); + boat.setVelocity(groundSpeed); + isStopped = false; + lastRotation = rotation; + boatAnnotations.update(); + + distanceTravelled += Math.sqrt((dx * dx) + (dy * dy)); + + if (distanceTravelled > 10 && isPlayer) { distanceTravelled = 0d; if (lastPoint != null) { @@ -190,45 +205,10 @@ public class BoatGroup extends Group { l.setCacheHint(CacheHint.SPEED); lineGroup.getChildren().add(l); } - if (destinationSet) { lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY()); } } -// wake.updatePosition(); - } - - /** - * Sets the destination of the boat and the headng it should have once it reaches - * - * @param newXValue The X co-ordinate the boat needs to move to. - * @param newYValue The Y co-ordinate the boat needs to move to. - * @param rotation Rotation to move graphics to. - * @param timeValid the time the position values are valid for - */ - public void setDestination(double newXValue, double newYValue, double rotation, - double groundSpeed, long timeValid, double frameRate) { - if (lastTimeValid == 0) { - lastTimeValid = timeValid - 200; - } - moveTo(newXValue, newYValue, rotation); -// framesToMove = Math.round((frameRate / (1000.0f / (timeValid - lastTimeValid)))); -// double dx = newXValue - boatPoly.getLayoutX(); -// double dy = newYValue - boatPoly.getLayoutY(); -// -// xIncrement = dx / framesToMove; -// yIncrement = dy / framesToMove; - - destinationSet = true; - - rotateTo(rotation); -// wake.rotate(rotation); - wake.setRotation(rotation, groundSpeed); - boat.setVelocity(groundSpeed); - lastTimeValid = timeValid; - isStopped = false; - lastRotation = rotation; - boatAnnotations.update(); }