diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java index 96753b94..3305d180 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 8faaca60..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(); } diff --git a/src/main/java/seng302/gameServer/MainServerThread.java b/src/main/java/seng302/gameServer/MainServerThread.java index 85d5c698..f72b17fd 100644 --- a/src/main/java/seng302/gameServer/MainServerThread.java +++ b/src/main/java/seng302/gameServer/MainServerThread.java @@ -23,7 +23,7 @@ import java.util.logging.Logger; public class MainServerThread extends Observable implements Runnable, ClientConnectionDelegate{ private static final int PORT = 4942; - private static final Integer CLIENT_UPDATES_PER_SECOND = 5; + private static final Integer CLIENT_UPDATES_PER_SECOND = 10; private static final int LOG_LEVEL = 1; private Thread thread;