diff --git a/src/main/java/seng302/gameServer/GameState.java b/src/main/java/seng302/gameServer/GameState.java index 150fd652..14550218 100644 --- a/src/main/java/seng302/gameServer/GameState.java +++ b/src/main/java/seng302/gameServer/GameState.java @@ -1,6 +1,5 @@ package seng302.gameServer; -import com.sun.corba.se.spi.activation.Server; import javafx.scene.paint.Color; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -263,10 +262,6 @@ public class GameState implements Runnable { if (currentStage == GameStages.RACING) { update(); } - - if (currentStage == GameStages.RACING) { - update(); - } } } @@ -639,23 +634,23 @@ public class GameState implements Runnable { Double trueWindAngle = Math.abs(windDirection - yacht.getHeading()); Double boatSpeedInKnots = PolarTable.getBoatSpeed(getWindSpeedKnots(), trueWindAngle); Double maxBoatSpeed = - GeoUtility.knotsToMMS(boatSpeedInKnots) * serverSpeedMultiplier * yacht.getSpeedMultiplier(); + GeoUtility.knotsToMMS(boatSpeedInKnots) * serverSpeedMultiplier * yacht.getSpeedMultiplier() * yacht.getMaxSpeedMultiplier(); Double currentVelocity = yacht.getCurrentVelocity(); // TODO: 15/08/17 remove magic numbers from these equations. if (yacht.getSailIn()) { if (currentVelocity < maxBoatSpeed - 500) { - yacht.changeVelocity(maxBoatSpeed / 100); + yacht.changeVelocity((maxBoatSpeed / 100) * yacht.getAccelerationMultiplier()); } else if (currentVelocity > maxBoatSpeed + 500) { - yacht.changeVelocity(-currentVelocity / 200); + yacht.changeVelocity((-currentVelocity / 200) * yacht.getAccelerationMultiplier()); } else { - yacht.setCurrentVelocity(maxBoatSpeed); + yacht.setCurrentVelocity((maxBoatSpeed) * yacht.getAccelerationMultiplier()); } } else { if (currentVelocity > 3000) { - yacht.changeVelocity(-currentVelocity / 200); + yacht.changeVelocity((-currentVelocity / 200) * yacht.getAccelerationMultiplier()); } else if (currentVelocity > 100) { - yacht.changeVelocity(-currentVelocity / 50); + yacht.changeVelocity((-currentVelocity / 50) * yacht.getAccelerationMultiplier()); } else if (currentVelocity <= 100) { yacht.setCurrentVelocity(0d); } diff --git a/src/main/java/seng302/model/ServerYacht.java b/src/main/java/seng302/model/ServerYacht.java index 21508774..d1f36c7c 100644 --- a/src/main/java/seng302/model/ServerYacht.java +++ b/src/main/java/seng302/model/ServerYacht.java @@ -8,8 +8,10 @@ import seng302.gameServer.messages.BoatStatus; import seng302.model.mark.Mark; import seng302.model.token.TokenType; import seng302.utilities.GeoUtility; +import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; import java.util.HashMap; +import java.util.Objects; import java.util.Observable; import java.util.Observer; import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; @@ -23,10 +25,12 @@ public class ServerYacht { private Logger logger = LoggerFactory.getLogger(ServerYacht.class); - public static final Double TURN_STEP = 5.0; - //Boat info private BoatMeshType boatType; + private Double turnStep = 5.0; + private Double maxSpeedMultiplier = 1.0; + private Double turnStepMultiplier = 1.0; + private Double accelerationMultiplier = 1.0; private Integer sourceId; private String hullID; //matches HullNum in the XML spec. private String shortName; @@ -62,7 +66,7 @@ public class ServerYacht { public ServerYacht(BoatMeshType boatType, Integer sourceId, String hullID, String shortName, String boatName, String country) { - this.boatType = boatType; + setBoatType(boatType); this.boatStatus = BoatStatus.PRESTART; this.sourceId = sourceId; this.hullID = hullID; @@ -136,7 +140,7 @@ public class ServerYacht { * @param amount the amount by which to adjust the boat heading. */ public void adjustHeading(Double amount) { - Double newVal = heading + amount * handlingMultiplier; + Double newVal = heading + amount * handlingMultiplier * turnStepMultiplier; lastHeading = heading; heading = (double) Math.floorMod(newVal.longValue(), 360L); } @@ -181,7 +185,7 @@ public class ServerYacht { if (isAuto) { turnTowardsHeading(autoHeading); if (Math.abs(heading - autoHeading) - <= TURN_STEP) { //Cancel when within 1 turn step of target. + <= turnStep) { //Cancel when within 1 turn step of target. isAuto = false; } } @@ -196,20 +200,20 @@ public class ServerYacht { Double normalizedHeading = normalizeHeading(); if (normalizedHeading == 0) { if (lastHeading < 180) { - adjustHeading(-TURN_STEP); + adjustHeading(-turnStep); } else { - adjustHeading(TURN_STEP); + adjustHeading(turnStep); } } else if (normalizedHeading == 180) { if (lastHeading < 180) { - adjustHeading(TURN_STEP); + adjustHeading(turnStep); } else { - adjustHeading(-TURN_STEP); + adjustHeading(-turnStep); } } else if (normalizedHeading < 180) { - adjustHeading(-TURN_STEP); + adjustHeading(-turnStep); } else { - adjustHeading(TURN_STEP); + adjustHeading(turnStep); } } @@ -218,20 +222,20 @@ public class ServerYacht { Double normalizedHeading = normalizeHeading(); if (normalizedHeading == 0) { if (lastHeading < 180) { - adjustHeading(TURN_STEP); + adjustHeading(turnStep); } else { - adjustHeading(-TURN_STEP); + adjustHeading(-turnStep); } } else if (normalizedHeading == 180) { if (lastHeading < 180) { - adjustHeading(-TURN_STEP); + adjustHeading(-turnStep); } else { - adjustHeading(TURN_STEP); + adjustHeading(turnStep); } } else if (normalizedHeading < 180) { - adjustHeading(TURN_STEP); + adjustHeading(turnStep); } else { - adjustHeading(-TURN_STEP); + adjustHeading(-turnStep); } } @@ -275,9 +279,9 @@ public class ServerYacht { private void turnTowardsHeading(Double newHeading) { Double newVal = heading - newHeading; if (Math.floorMod(newVal.longValue(), 360L) > 180) { - adjustHeading(TURN_STEP / 5); + adjustHeading(turnStep / 5); } else { - adjustHeading(-TURN_STEP / 5); + adjustHeading(-turnStep / 5); } } @@ -429,9 +433,21 @@ public class ServerYacht { } public void setBoatType(BoatMeshType boatType) { + this.accelerationMultiplier = boatType.accelerationMultiplier; + this.maxSpeedMultiplier = boatType.maxSpeedMultiplier; + this.turnStepMultiplier = boatType.turnStep; this.boatType = boatType; } + public Double getMaxSpeedMultiplier() { + return maxSpeedMultiplier; + } + + public Double getAccelerationMultiplier(){ + return accelerationMultiplier; + } + + public BoatMeshType getBoatType() { return boatType; } diff --git a/src/main/java/seng302/utilities/Sounds.java b/src/main/java/seng302/utilities/Sounds.java index 944fa93f..f8257b1f 100644 --- a/src/main/java/seng302/utilities/Sounds.java +++ b/src/main/java/seng302/utilities/Sounds.java @@ -14,8 +14,10 @@ public class Sounds { private static MediaPlayer soundEffect; private static MediaPlayer soundPlayer; private static MediaPlayer hoverSoundPlayer; + private static MediaPlayer crashSoundPlayer; private static boolean hoverInitialized = false; + private static boolean crashInitialized = false; private static boolean musicMuted = false; private static boolean soundEffectsMuted = false; @@ -155,11 +157,17 @@ public class Sounds { public static void playCrashSound() { if (!soundEffectsMuted) { - Media crashSound = new Media( - Sounds.class.getClassLoader().getResource("sounds/Large-metal-door-slam.mp3") - .toString()); - soundPlayer = new MediaPlayer(crashSound); - soundPlayer.play(); + if (!crashInitialized) { + Media pickupSound = new Media( + Sounds.class.getClassLoader().getResource("sounds/Large-metal-door-slam.mp3") + .toString()); + crashSoundPlayer = new MediaPlayer(pickupSound); + crashInitialized = true; + } + if (crashSoundPlayer != null) { + crashSoundPlayer.stop(); + } + crashSoundPlayer.play(); } } @@ -176,10 +184,10 @@ public class Sounds { public static void playHoverSound() { if (!soundEffectsMuted) { if (!hoverInitialized) { - Media crashSound = new Media( + Media hoverSound = new Media( Sounds.class.getClassLoader().getResource("sounds/Error-sound-effect.mp3") .toString()); - hoverSoundPlayer = new MediaPlayer(crashSound); + hoverSoundPlayer = new MediaPlayer(hoverSound); hoverInitialized = true; } hoverSoundPlayer.setVolume(0.5); diff --git a/src/main/java/seng302/visualiser/controllers/LobbyController.java b/src/main/java/seng302/visualiser/controllers/LobbyController.java index 67b1dfbd..aa8430b8 100644 --- a/src/main/java/seng302/visualiser/controllers/LobbyController.java +++ b/src/main/java/seng302/visualiser/controllers/LobbyController.java @@ -131,7 +131,7 @@ public class LobbyController implements Initializable { .get(ViewManager.getInstance().getGameClient().getServerThread().getClientId()) .getBoatName()); controller.setCurrentBoat(this.playerBoats.get(ViewManager.getInstance().getGameClient().getServerThread().getClientId()) - .getBoatType()); + .getBoatType().toString()); return customizationDialog; } diff --git a/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java b/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java index 4b02ac9a..67fb089a 100644 --- a/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java +++ b/src/main/java/seng302/visualiser/controllers/dialogs/BoatCustomizeController.java @@ -11,6 +11,7 @@ import javafx.fxml.Initializable; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.PointLight; +import javafx.scene.control.ProgressBar; import javafx.scene.layout.Background; import javafx.scene.layout.BackgroundFill; import javafx.scene.layout.CornerRadii; @@ -33,6 +34,12 @@ public class BoatCustomizeController implements Initializable{ @FXML private JFXColorPicker colorPicker; @FXML + private ProgressBar speedBar; + @FXML + private ProgressBar accelBar; + @FXML + private ProgressBar handleBar; + @FXML private JFXButton submitBtn; @FXML private JFXTextField boatName; @@ -47,12 +54,15 @@ public class BoatCustomizeController implements Initializable{ private ClientToServerThread socketThread; private LobbyController lobbyController; private BoatMeshType currentBoat; + private Double maxSpeedMultiplier = 1.0; + private Double maxTurnRateMultiplier = 1.0; + private Double maxAccelerationMultiplier = 1.0; @Override public void initialize(URL location, ResourceBundle resources) { socketThread = ViewManager.getInstance().getGameClient().getServerThread(); - + findMaxStats(); RequiredFieldValidator playerNameReqValidator = new RequiredFieldValidator(); playerNameReqValidator.setMessage("Player name required."); @@ -111,19 +121,23 @@ public class BoatCustomizeController implements Initializable{ this.lobbyController = lobbyController; } - public void setCurrentBoat(BoatMeshType boatType) { - currentBoat = boatType; + public void setCurrentBoat(String boatType) { + currentBoat = BoatMeshType.valueOf(boatType); displayCurrentBoat(); + refreshStatBars(currentBoat); } public void nextBoat() { currentBoat = BoatMeshType.getNextBoatType(currentBoat); displayCurrentBoat(); + refreshStatBars(currentBoat); } public void prevBoat() { currentBoat = BoatMeshType.getPrevBoatType(currentBoat); displayCurrentBoat(); + refreshStatBars(currentBoat); + } private void displayCurrentBoat() { @@ -141,5 +155,26 @@ public class BoatCustomizeController implements Initializable{ boatPane.getChildren().add(group); BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue()); group.getChildren().add(bo.getAssets()); + refreshStatBars(currentBoat); + } + + private void findMaxStats() { + for (BoatMeshType bmt: BoatMeshType.values()) { + if (bmt.turnStep > maxTurnRateMultiplier) { + maxTurnRateMultiplier = bmt.turnStep; + } + if (bmt.maxSpeedMultiplier > maxSpeedMultiplier) { + maxSpeedMultiplier = bmt.maxSpeedMultiplier; + } + if (bmt.accelerationMultiplier > maxAccelerationMultiplier) { + maxAccelerationMultiplier = bmt.accelerationMultiplier; + } + } + } + + private void refreshStatBars(BoatMeshType bo) { + speedBar.setProgress((bo.maxSpeedMultiplier) / maxSpeedMultiplier); + accelBar.setProgress(bo.accelerationMultiplier / maxAccelerationMultiplier); + handleBar.setProgress(bo.turnStep / maxTurnRateMultiplier); } } diff --git a/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatMeshType.java b/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatMeshType.java index 65c9714c..292c636a 100644 --- a/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatMeshType.java +++ b/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatMeshType.java @@ -7,19 +7,22 @@ package seng302.visualiser.fxObjects.assets_3D; */ public enum BoatMeshType { - DINGHY("dinghy_hull.stl", "dinghy_mast.stl", 1.36653, "dinghy_sail.stl", 1.36653, null, false), - CAT_ATE_A_MERINGUE("catamaran_hull.stl", "catamaran_mast.stl", 0.997, "catamaran_sail.stl", - 0.997, null, false), + DINGHY("dinghy_hull.stl", "dinghy_mast.stl", 1.36653, "dinghy_sail.stl", 1.36653, null, false, 1.8, 1.0, 1.0), + CATAMARAN("catamaran_hull.stl", "catamaran_mast.stl", 0.997, "catamaran_sail.stl", + 0.997, null, false, 1.0, 1.4, 2.0), PIRATE_SHIP("pirateship_hull.stl", "pirateship_mast.stl", -0.5415, "pirateship_mainsail.stl", - -0.5415, "pirateship_frontsail.stl", true); + -0.5415, "pirateship_frontsail.stl", true, 1.2, 1.6, 1.2); final String hullFile, mastFile, sailFile, jibFile; final double mastOffset, sailOffset; + public final double maxSpeedMultiplier; + public final double accelerationMultiplier; + public final double turnStep; final boolean fixedSail; - final static BoatMeshType[] boatTypes = new BoatMeshType[]{DINGHY, CAT_ATE_A_MERINGUE, PIRATE_SHIP}; + final static BoatMeshType[] boatTypes = new BoatMeshType[]{DINGHY, CATAMARAN, PIRATE_SHIP}; BoatMeshType(String hullFile, String mastFile, double mastOffset, String sailFile, - double sailOffset, String jibFile, boolean fixedSail) { + double sailOffset, String jibFile, boolean fixedSail, double maxSpeedMultiplier, double accelerationMultiplier, double turnStep) { this.hullFile = hullFile; this.mastFile = mastFile; this.mastOffset = mastOffset; @@ -27,10 +30,12 @@ public enum BoatMeshType { this.sailOffset = sailOffset; this.jibFile = jibFile; this.fixedSail = fixedSail; + this.maxSpeedMultiplier = maxSpeedMultiplier; + this.accelerationMultiplier = accelerationMultiplier; + this.turnStep = turnStep; } - //TODO kre39 make something not terrible to cycle through boat types public static BoatMeshType getNextBoatType(BoatMeshType boatType) { for (int i = 0; i < boatTypes.length; i++) { if (i == boatTypes.length -1) { diff --git a/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatModel.java b/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatModel.java index 0562d4f7..e056b14d 100644 --- a/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatModel.java +++ b/src/main/java/seng302/visualiser/fxObjects/assets_3D/BoatModel.java @@ -71,4 +71,8 @@ public class BoatModel extends Model { private MeshView getMeshViewChild(int index) { return (MeshView) assets.getChildren().get(index); } + + public BoatMeshType getMeshType() { + return meshType; + } } \ No newline at end of file diff --git a/src/main/resources/views/dialogs/BoatCustomizeDialog.fxml b/src/main/resources/views/dialogs/BoatCustomizeDialog.fxml index 1d355a33..809b96a2 100644 --- a/src/main/resources/views/dialogs/BoatCustomizeDialog.fxml +++ b/src/main/resources/views/dialogs/BoatCustomizeDialog.fxml @@ -1,5 +1,6 @@ + @@ -24,6 +25,7 @@ + @@ -31,12 +33,12 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/seng302/utilities/BoatMeshTypeTest.java b/src/test/java/seng302/utilities/BoatMeshTypeTest.java index 743c7f1e..8f0d30b9 100644 --- a/src/test/java/seng302/utilities/BoatMeshTypeTest.java +++ b/src/test/java/seng302/utilities/BoatMeshTypeTest.java @@ -15,12 +15,12 @@ public class BoatMeshTypeTest { public void testNextBoatMeshType() { BoatMeshType currentBoat = BoatMeshType.DINGHY; BoatMeshType nextBoat = BoatMeshType.getNextBoatType(currentBoat); - Assert.assertEquals(BoatMeshType.CAT_ATE_A_MERINGUE, nextBoat); + Assert.assertEquals(BoatMeshType.CATAMARAN, nextBoat); } @Test public void testPreviousBoatMeshType() { - BoatMeshType currentBoat = BoatMeshType.CAT_ATE_A_MERINGUE; + BoatMeshType currentBoat = BoatMeshType.CATAMARAN; BoatMeshType prevBoat = BoatMeshType.getPrevBoatType(currentBoat); Assert.assertEquals(BoatMeshType.DINGHY, prevBoat); } diff --git a/src/test/java/steps/ToggleSailSteps.java b/src/test/java/steps/ToggleSailSteps.java index 4bf20242..5c82a614 100644 --- a/src/test/java/steps/ToggleSailSteps.java +++ b/src/test/java/steps/ToggleSailSteps.java @@ -13,6 +13,7 @@ import seng302.model.ServerYacht; import seng302.visualiser.ClientToServerThread; /** + * * Created by kre39 on 7/08/17. */ public class ToggleSailSteps {