Started working on individual boat stats. Already modified turning rate. Need to add a vsual component.

#story[1274]
This commit is contained in:
Kusal Ekanayake
2017-09-22 13:52:35 +12:00
parent c4a6113f6c
commit faeece27ff
2 changed files with 26 additions and 20 deletions
@@ -453,6 +453,7 @@ public class GameState implements Runnable {
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;
} }
} }
+25 -20
View File
@@ -8,10 +8,9 @@ import seng302.gameServer.messages.BoatStatus;
import seng302.model.mark.Mark; import seng302.model.mark.Mark;
import seng302.model.token.TokenType; import seng302.model.token.TokenType;
import seng302.utilities.GeoUtility; import seng302.utilities.GeoUtility;
import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
import java.util.HashMap; import java.util.HashMap;
import java.util.Observable;
import java.util.Observer;
/** /**
* Yacht class for the racing boat. <p> Class created to store more variables (eg. boat statuses) * Yacht class for the racing boat. <p> Class created to store more variables (eg. boat statuses)
@@ -22,10 +21,9 @@ public class ServerYacht {
private Logger logger = LoggerFactory.getLogger(ClientYacht.class); private Logger logger = LoggerFactory.getLogger(ClientYacht.class);
public static final Double TURN_STEP = 5.0;
//Boat info //Boat info
private String boatType; private String boatType;
private Double turn_step;
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;
@@ -59,7 +57,7 @@ public class ServerYacht {
public ServerYacht(String boatType, Integer sourceId, String hullID, String shortName, public ServerYacht(String boatType, Integer sourceId, String hullID, String shortName,
String boatName, String country) { String boatName, String country) {
this.boatType = boatType; setBoatType(boatType);
this.boatStatus = BoatStatus.PRESTART; this.boatStatus = BoatStatus.PRESTART;
this.sourceId = sourceId; this.sourceId = sourceId;
this.hullID = hullID; this.hullID = hullID;
@@ -174,7 +172,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. <= turn_step) { //Cancel when within 1 turn step of target.
isAuto = false; isAuto = false;
} }
} }
@@ -189,20 +187,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(-turn_step);
} else { } else {
adjustHeading(TURN_STEP); adjustHeading(turn_step);
} }
} else if (normalizedHeading == 180) { } else if (normalizedHeading == 180) {
if (lastHeading < 180) { if (lastHeading < 180) {
adjustHeading(TURN_STEP); adjustHeading(turn_step);
} else { } else {
adjustHeading(-TURN_STEP); adjustHeading(-turn_step);
} }
} else if (normalizedHeading < 180) { } else if (normalizedHeading < 180) {
adjustHeading(-TURN_STEP); adjustHeading(-turn_step);
} else { } else {
adjustHeading(TURN_STEP); adjustHeading(turn_step);
} }
} }
@@ -211,20 +209,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(turn_step);
} else { } else {
adjustHeading(-TURN_STEP); adjustHeading(-turn_step);
} }
} else if (normalizedHeading == 180) { } else if (normalizedHeading == 180) {
if (lastHeading < 180) { if (lastHeading < 180) {
adjustHeading(-TURN_STEP); adjustHeading(-turn_step);
} else { } else {
adjustHeading(TURN_STEP); adjustHeading(turn_step);
} }
} else if (normalizedHeading < 180) { } else if (normalizedHeading < 180) {
adjustHeading(TURN_STEP); adjustHeading(turn_step);
} else { } else {
adjustHeading(-TURN_STEP); adjustHeading(-turn_step);
} }
} }
@@ -268,9 +266,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(turn_step / 5);
} else { } else {
adjustHeading(-TURN_STEP / 5); adjustHeading(-turn_step / 5);
} }
} }
@@ -422,6 +420,13 @@ public class ServerYacht {
} }
public void setBoatType(String boatType) { public void setBoatType(String boatType) {
if (boatType == BoatMeshType.DINGHY.toString()) {
turn_step = 5.0;
} else if (boatType == BoatMeshType.CAT_ATE_A_MERINGUE.toString()){
turn_step = 10.0;
} else {
turn_step = 7.0;
}
this.boatType = boatType; this.boatType = boatType;
} }