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 maxBoatSpeed = GeoUtility.knotsToMMS(boatSpeedInKnots);
yacht.setCurrentMaxVelocity(maxBoatSpeed);
if (yacht.getSailIn() && yacht.getCurrentVelocity() <= maxBoatSpeed && maxBoatSpeed != 0d) {
if (velocity < maxBoatSpeed) {
yacht.changeVelocity(maxBoatSpeed / 15);
}
if (velocity > maxBoatSpeed) {
System.out.println(maxBoatSpeed);
// TODO: 15/08/17 remove magic numbers from these equations.
if (yacht.getSailIn()) {
if (velocity < maxBoatSpeed - 500) {
yacht.changeVelocity(maxBoatSpeed / 150);
} else if (velocity > maxBoatSpeed + 500) {
yacht.changeVelocity(-maxBoatSpeed / 100);
} else {
yacht.setCurrentVelocity(maxBoatSpeed);
}
} else {
if (velocity > 0d) {
if (maxBoatSpeed != 0d) {
yacht.changeVelocity(-maxBoatSpeed / 600);
} else {
yacht.changeVelocity(-velocity / 100);
}
if (velocity < 0) {
yacht.setCurrentVelocity(0d);
}
if (velocity > 3000) {
yacht.changeVelocity(-velocity / 200);
} else if (velocity > 100) {
yacht.changeVelocity(-velocity / 50);
} else if (velocity <= 100){
yacht.setCurrentVelocity(0d);
}
}
}