Changed the velocity equation for boats to handle outlying scenarios such as 0 velocity.

#bug
This commit is contained in:
Calum
2017-08-15 15:12:39 +12:00
parent baacd8a9c0
commit d2bb15471a
+14 -15
View File
@@ -232,24 +232,23 @@ public class GameState implements Runnable {
Double boatSpeedInKnots = PolarTable.getBoatSpeed(getWindSpeedKnots(), trueWindAngle); Double boatSpeedInKnots = PolarTable.getBoatSpeed(getWindSpeedKnots(), trueWindAngle);
Double maxBoatSpeed = GeoUtility.knotsToMMS(boatSpeedInKnots); Double maxBoatSpeed = GeoUtility.knotsToMMS(boatSpeedInKnots);
yacht.setCurrentMaxVelocity(maxBoatSpeed); yacht.setCurrentMaxVelocity(maxBoatSpeed);
System.out.println(maxBoatSpeed);
if (yacht.getSailIn() && yacht.getCurrentVelocity() <= maxBoatSpeed && maxBoatSpeed != 0d) { // TODO: 15/08/17 remove magic numbers from these equations.
if (velocity < maxBoatSpeed) { if (yacht.getSailIn()) {
yacht.changeVelocity(maxBoatSpeed / 15); if (velocity < maxBoatSpeed - 500) {
} yacht.changeVelocity(maxBoatSpeed / 150);
if (velocity > maxBoatSpeed) { } else if (velocity > maxBoatSpeed + 500) {
yacht.changeVelocity(-maxBoatSpeed / 100);
} else {
yacht.setCurrentVelocity(maxBoatSpeed); yacht.setCurrentVelocity(maxBoatSpeed);
} }
} else { } else {
if (velocity > 0d) { if (velocity > 3000) {
if (maxBoatSpeed != 0d) { yacht.changeVelocity(-velocity / 200);
yacht.changeVelocity(-maxBoatSpeed / 600); } else if (velocity > 100) {
} else { yacht.changeVelocity(-velocity / 50);
yacht.changeVelocity(-velocity / 100); } else if (velocity <= 100){
} yacht.setCurrentVelocity(0d);
if (velocity < 0) {
yacht.setCurrentVelocity(0d);
}
} }
} }
} }