Worked on making a visual component to the stats. Need to implement acceleration.

#story[1274]
This commit is contained in:
Kusal Ekanayake
2017-09-22 16:45:10 +12:00
parent faeece27ff
commit b05580f018
6 changed files with 108 additions and 32 deletions
@@ -449,11 +449,10 @@ public class GameState implements Runnable {
private void updateVelocity(ServerYacht yacht) { private void updateVelocity(ServerYacht yacht) {
Double trueWindAngle = Math.abs(windDirection - yacht.getHeading()); Double trueWindAngle = Math.abs(windDirection - yacht.getHeading());
Double boatSpeedInKnots = PolarTable.getBoatSpeed(getWindSpeedKnots(), trueWindAngle); Double boatSpeedInKnots = PolarTable.getBoatSpeed(getWindSpeedKnots(), trueWindAngle);
Double maxBoatSpeed = GeoUtility.knotsToMMS(boatSpeedInKnots) * speedMultiplier; Double maxBoatSpeed = GeoUtility.knotsToMMS(boatSpeedInKnots) * speedMultiplier * yacht.getMaxSpeedMultiplier();
if (yacht.getPowerUp() != null) { if (yacht.getPowerUp() != null) {
if (yacht.getPowerUp().equals(TokenType.BOOST)) { if (yacht.getPowerUp().equals(TokenType.BOOST)) {
// TODO: 11/09/17 wmu16 CHANGE THIS TO MAGIC NUMBER // TODO: 11/09/17 wmu16 CHANGE THIS TO MAGIC NUMBER
// TODO 22/09/17 kre39 change this magic number to a variable
maxBoatSpeed *= 2; maxBoatSpeed *= 2;
} }
} }
+28 -22
View File
@@ -23,7 +23,8 @@ public class ServerYacht {
//Boat info //Boat info
private String boatType; private String boatType;
private Double turn_step; private Double turnStep = 10.0;
private Double maxSpeedMultiplier = 1.0;
private Integer sourceId; private Integer sourceId;
private String hullID; //matches HullNum in the XML spec. private String hullID; //matches HullNum in the XML spec.
private String shortName; private String shortName;
@@ -172,7 +173,7 @@ public class ServerYacht {
if (isAuto) { if (isAuto) {
turnTowardsHeading(autoHeading); turnTowardsHeading(autoHeading);
if (Math.abs(heading - 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; isAuto = false;
} }
} }
@@ -187,20 +188,20 @@ public class ServerYacht {
Double normalizedHeading = normalizeHeading(); Double normalizedHeading = normalizeHeading();
if (normalizedHeading == 0) { if (normalizedHeading == 0) {
if (lastHeading < 180) { if (lastHeading < 180) {
adjustHeading(-turn_step); adjustHeading(-turnStep);
} else { } else {
adjustHeading(turn_step); adjustHeading(turnStep);
} }
} else if (normalizedHeading == 180) { } else if (normalizedHeading == 180) {
if (lastHeading < 180) { if (lastHeading < 180) {
adjustHeading(turn_step); adjustHeading(turnStep);
} else { } else {
adjustHeading(-turn_step); adjustHeading(-turnStep);
} }
} else if (normalizedHeading < 180) { } else if (normalizedHeading < 180) {
adjustHeading(-turn_step); adjustHeading(-turnStep);
} else { } else {
adjustHeading(turn_step); adjustHeading(turnStep);
} }
} }
@@ -209,20 +210,20 @@ public class ServerYacht {
Double normalizedHeading = normalizeHeading(); Double normalizedHeading = normalizeHeading();
if (normalizedHeading == 0) { if (normalizedHeading == 0) {
if (lastHeading < 180) { if (lastHeading < 180) {
adjustHeading(turn_step); adjustHeading(turnStep);
} else { } else {
adjustHeading(-turn_step); adjustHeading(-turnStep);
} }
} else if (normalizedHeading == 180) { } else if (normalizedHeading == 180) {
if (lastHeading < 180) { if (lastHeading < 180) {
adjustHeading(-turn_step); adjustHeading(-turnStep);
} else { } else {
adjustHeading(turn_step); adjustHeading(turnStep);
} }
} else if (normalizedHeading < 180) { } else if (normalizedHeading < 180) {
adjustHeading(turn_step); adjustHeading(turnStep);
} else { } else {
adjustHeading(-turn_step); adjustHeading(-turnStep);
} }
} }
@@ -266,9 +267,9 @@ public class ServerYacht {
private void turnTowardsHeading(Double newHeading) { private void turnTowardsHeading(Double newHeading) {
Double newVal = heading - newHeading; Double newVal = heading - newHeading;
if (Math.floorMod(newVal.longValue(), 360L) > 180) { if (Math.floorMod(newVal.longValue(), 360L) > 180) {
adjustHeading(turn_step / 5); adjustHeading(turnStep / 5);
} else { } else {
adjustHeading(-turn_step / 5); adjustHeading(-turnStep / 5);
} }
} }
@@ -420,16 +421,21 @@ public class ServerYacht {
} }
public void setBoatType(String boatType) { public void setBoatType(String boatType) {
if (boatType == BoatMeshType.DINGHY.toString()) { BoatMeshType boatMeshType;
turn_step = 5.0; for (BoatMeshType boatMesh: BoatMeshType.values()) {
} else if (boatType == BoatMeshType.CAT_ATE_A_MERINGUE.toString()){ if (boatType == boatMesh.toString()) {
turn_step = 10.0; boatMeshType = boatMesh;
} else { turnStep = boatMeshType.turnStep;
turn_step = 7.0; maxSpeedMultiplier = boatMeshType.maxSpeedMultiplier;
}
} }
this.boatType = boatType; this.boatType = boatType;
} }
public Double getMaxSpeedMultiplier() {
return maxSpeedMultiplier;
}
public String getBoatType() { public String getBoatType() {
return boatType; return boatType;
} }
@@ -12,6 +12,7 @@ import javafx.fxml.Initializable;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.PointLight; import javafx.scene.PointLight;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.Background; import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill; import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii; import javafx.scene.layout.CornerRadii;
@@ -34,6 +35,12 @@ public class BoatCustomizeController implements Initializable{
@FXML @FXML
private JFXColorPicker colorPicker; private JFXColorPicker colorPicker;
@FXML @FXML
private ProgressBar speedBar;
@FXML
private ProgressBar accelBar;
@FXML
private ProgressBar handleBar;
@FXML
private JFXButton submitBtn; private JFXButton submitBtn;
@FXML @FXML
private JFXTextField boatName; private JFXTextField boatName;
@@ -49,12 +56,15 @@ public class BoatCustomizeController implements Initializable{
private ClientToServerThread socketThread; private ClientToServerThread socketThread;
private LobbyController lobbyController; private LobbyController lobbyController;
private BoatMeshType currentBoat; private BoatMeshType currentBoat;
private static Double maxSpeedMultiplier = 1.0;
private static Double maxTurnRate = 10.0;
private static Double maxAcceleration = 2.0;
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
socketThread = ViewManager.getInstance().getGameClient().getServerThread(); socketThread = ViewManager.getInstance().getGameClient().getServerThread();
generateMaxStats();
RequiredFieldValidator playerNameReqValidator = new RequiredFieldValidator(); RequiredFieldValidator playerNameReqValidator = new RequiredFieldValidator();
playerNameReqValidator.setMessage("Player name required."); playerNameReqValidator.setMessage("Player name required.");
@@ -120,6 +130,8 @@ public class BoatCustomizeController implements Initializable{
BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue()); BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue());
group.getChildren().add(bo.getAssets()); group.getChildren().add(bo.getAssets());
group.getChildren().add(new PointLight()); group.getChildren().add(new PointLight());
refreshStatBars(bo);
} }
public void nextBoat(ActionEvent actionEvent) { public void nextBoat(ActionEvent actionEvent) {
@@ -130,6 +142,8 @@ public class BoatCustomizeController implements Initializable{
BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue()); BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue());
group.getChildren().add(bo.getAssets()); group.getChildren().add(bo.getAssets());
group.getChildren().add(new PointLight()); group.getChildren().add(new PointLight());
refreshStatBars(bo);
} }
public void prevBoat(ActionEvent actionEvent) { public void prevBoat(ActionEvent actionEvent) {
@@ -140,6 +154,8 @@ public class BoatCustomizeController implements Initializable{
BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue()); BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue());
group.getChildren().add(bo.getAssets()); group.getChildren().add(bo.getAssets());
group.getChildren().add(new PointLight()); group.getChildren().add(new PointLight());
refreshStatBars(bo);
} }
private void RefreshBoat() { private void RefreshBoat() {
@@ -148,5 +164,26 @@ public class BoatCustomizeController implements Initializable{
boatPane.getChildren().add(group); boatPane.getChildren().add(group);
BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue()); BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue());
group.getChildren().add(bo.getAssets()); group.getChildren().add(bo.getAssets());
refreshStatBars(bo);
}
private void generateMaxStats() {
for (BoatMeshType bmt: BoatMeshType.values()) {
if (bmt.turnStep > maxTurnRate) {
maxTurnRate = bmt.turnStep;
}
if (bmt.maxSpeedMultiplier > maxSpeedMultiplier) {
maxSpeedMultiplier = bmt.maxSpeedMultiplier;
}
if (bmt.accelerationMultiplier > maxAcceleration) {
maxAcceleration = bmt.accelerationMultiplier;
}
}
}
private void refreshStatBars(BoatModel bo) {
speedBar.setProgress((bo.getMeshType().maxSpeedMultiplier) / maxSpeedMultiplier);
accelBar.setProgress(bo.getMeshType().accelerationMultiplier / maxAcceleration);
handleBar.setProgress(bo.getMeshType().turnStep / maxTurnRate);
} }
} }
@@ -7,19 +7,22 @@ package seng302.visualiser.fxObjects.assets_3D;
*/ */
public enum BoatMeshType { public enum BoatMeshType {
DINGHY("dinghy_hull.stl", "dinghy_mast.stl", 1.36653, "dinghy_sail.stl", 1.36653, null, false), DINGHY("dinghy_hull.stl", "dinghy_mast.stl", 1.36653, "dinghy_sail.stl", 1.36653, null, false, 1.5, 1.0, 5.0),
CAT_ATE_A_MERINGUE("catamaran_hull.stl", "catamaran_mast.stl", 0.997, "catamaran_sail.stl", CAT_ATE_A_MERINGUE("catamaran_hull.stl", "catamaran_mast.stl", 0.997, "catamaran_sail.stl",
0.997, null, false), 0.997, null, false, 1.0, 1.0, 10.0),
PIRATE_SHIP("pirateship_hull.stl", "pirateship_mast.stl", -0.5415, "pirateship_mainsail.stl", 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.0, 7.0);
final String hullFile, mastFile, sailFile, jibFile; final String hullFile, mastFile, sailFile, jibFile;
final double mastOffset, sailOffset; final double mastOffset, sailOffset;
public final double maxSpeedMultiplier;
public final double accelerationMultiplier;
public final double turnStep;
final boolean fixedSail; final boolean fixedSail;
final static BoatMeshType[] boatTypes = new BoatMeshType[]{DINGHY, CAT_ATE_A_MERINGUE, PIRATE_SHIP}; final static BoatMeshType[] boatTypes = new BoatMeshType[]{DINGHY, CAT_ATE_A_MERINGUE, PIRATE_SHIP};
BoatMeshType(String hullFile, String mastFile, double mastOffset, String sailFile, 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.hullFile = hullFile;
this.mastFile = mastFile; this.mastFile = mastFile;
this.mastOffset = mastOffset; this.mastOffset = mastOffset;
@@ -27,6 +30,9 @@ public enum BoatMeshType {
this.sailOffset = sailOffset; this.sailOffset = sailOffset;
this.jibFile = jibFile; this.jibFile = jibFile;
this.fixedSail = fixedSail; this.fixedSail = fixedSail;
this.maxSpeedMultiplier = maxSpeedMultiplier;
this.accelerationMultiplier = accelerationMultiplier;
this.turnStep = turnStep;
} }
public static BoatMeshType getBoatMeshType(String boatType) { public static BoatMeshType getBoatMeshType(String boatType) {
@@ -18,6 +18,9 @@ public class BoatModel extends Model {
private static final int SAIL_INDEX = 2; private static final int SAIL_INDEX = 2;
private BoatMeshType meshType; private BoatMeshType meshType;
private Double maxSpeedMultiplier;
private Double turnStep;
private Double accelerationMultiplier;
/** /**
* Stores a model and it's optional animation. * Stores a model and it's optional animation.
@@ -71,4 +74,8 @@ public class BoatModel extends Model {
private MeshView getMeshViewChild(int index) { private MeshView getMeshViewChild(int index) {
return (MeshView) assets.getChildren().get(index); return (MeshView) assets.getChildren().get(index);
} }
public BoatMeshType getMeshType() {
return meshType;
}
} }
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import com.jfoenix.controls.*?> <?import com.jfoenix.controls.*?>
<?import java.lang.*?> <?import java.lang.*?>
<?import javafx.geometry.*?> <?import javafx.geometry.*?>
@@ -24,6 +25,7 @@
</columnConstraints> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints maxHeight="90.0" minHeight="48.0" prefHeight="48.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="90.0" minHeight="48.0" prefHeight="48.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="207.0" minHeight="93.0" prefHeight="181.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="207.0" minHeight="93.0" prefHeight="181.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="207.0" minHeight="93.0" prefHeight="181.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="145.0" minHeight="66.0" prefHeight="109.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="145.0" minHeight="66.0" prefHeight="109.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="125.0" minHeight="24.0" prefHeight="72.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="125.0" minHeight="24.0" prefHeight="72.0" vgrow="SOMETIMES" />
@@ -31,12 +33,12 @@
</rowConstraints> </rowConstraints>
<children> <children>
<Label fx:id="hostDialogHeader" text="Customize Boat" GridPane.halignment="CENTER" GridPane.valignment="CENTER" /> <Label fx:id="hostDialogHeader" text="Customize Boat" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
<JFXButton fx:id="submitBtn" prefHeight="45.0" prefWidth="220.0" text="Customize Boat" GridPane.halignment="CENTER" GridPane.rowIndex="4" GridPane.valignment="CENTER" /> <JFXButton fx:id="submitBtn" prefHeight="45.0" prefWidth="220.0" text="Customize Boat" GridPane.halignment="CENTER" GridPane.rowIndex="5" GridPane.valignment="CENTER" />
<JFXTextField fx:id="boatName" focusColor="#6c6c6c" promptText="Boat Name" unFocusColor="#6b6b6b" GridPane.rowIndex="2"> <JFXTextField fx:id="boatName" focusColor="#6c6c6c" promptText="Boat Name" unFocusColor="#6b6b6b" GridPane.rowIndex="3">
<GridPane.margin> <GridPane.margin>
<Insets left="30.0" right="30.0" /> <Insets left="30.0" right="30.0" />
</GridPane.margin></JFXTextField> </GridPane.margin></JFXTextField>
<GridPane GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER"> <GridPane GridPane.halignment="CENTER" GridPane.rowIndex="4" GridPane.valignment="CENTER">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="139.0" minWidth="10.0" prefWidth="94.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="139.0" minWidth="10.0" prefWidth="94.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="203.0" minWidth="10.0" prefWidth="198.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="203.0" minWidth="10.0" prefWidth="198.0" />
@@ -75,6 +77,25 @@
<JFXButton buttonType="RAISED" onAction="#nextBoat" prefHeight="200.0" prefWidth="50.0" text="&gt;" GridPane.columnIndex="2" /> <JFXButton buttonType="RAISED" onAction="#nextBoat" prefHeight="200.0" prefWidth="50.0" text="&gt;" GridPane.columnIndex="2" />
</children> </children>
</GridPane> </GridPane>
<GridPane GridPane.rowIndex="2">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Max Speed:" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Acceleration:" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Handling:" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="CENTER" />
<ProgressBar fx:id="speedBar" focusTraversable="false" prefWidth="200.0" progress="0.0" GridPane.columnIndex="1" />
<ProgressBar fx:id="accelBar" prefWidth="200.0" progress="0.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<ProgressBar fx:id="handleBar" prefWidth="200.0" progress="0.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
</GridPane>
</children> </children>
</GridPane> </GridPane>
</children> </children>