mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Fixed a bug where if boatMaxSpeed was 0 and sails were up, boat would not decelerate.
#story[986]
This commit is contained in:
@@ -117,19 +117,40 @@ public class Yacht {
|
|||||||
* @param timeInterval since last update in milliseconds
|
* @param timeInterval since last update in milliseconds
|
||||||
*/
|
*/
|
||||||
public void update(Long timeInterval) {
|
public void update(Long timeInterval) {
|
||||||
if (sailIn) {
|
|
||||||
Double secondsElapsed = timeInterval / 1000000.0;
|
Double secondsElapsed = timeInterval / 1000000.0;
|
||||||
Double windSpeedKnots = GameState.getWindSpeedKnots();
|
Double windSpeedKnots = GameState.getWindSpeedKnots();
|
||||||
Double trueWindAngle = Math.abs(GameState.getWindDirection() - heading);
|
Double trueWindAngle = Math.abs(GameState.getWindDirection() - heading);
|
||||||
Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, trueWindAngle);
|
Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, trueWindAngle);
|
||||||
velocity = boatSpeedInKnots / ClientPacketParser.MS_TO_KNOTS * 1000;
|
Double maxBoatSpeed = boatSpeedInKnots / ClientPacketParser.MS_TO_KNOTS * 1000;
|
||||||
Double metersCovered = velocity * secondsElapsed;
|
if (sailIn && velocity <= maxBoatSpeed && maxBoatSpeed != 0d) {
|
||||||
location = getGeoCoordinate(location, heading, metersCovered);
|
|
||||||
|
if (velocity < maxBoatSpeed) {
|
||||||
|
velocity += maxBoatSpeed / 15; // Acceleration
|
||||||
|
}
|
||||||
|
if (velocity > maxBoatSpeed) {
|
||||||
|
velocity = maxBoatSpeed; // Prevent the boats from exceeding top speed
|
||||||
|
}
|
||||||
|
|
||||||
|
} else { // Deceleration
|
||||||
|
|
||||||
|
if (velocity > 0d) {
|
||||||
|
if (maxBoatSpeed != 0d) {
|
||||||
|
velocity -= maxBoatSpeed / 25;
|
||||||
} else {
|
} else {
|
||||||
|
velocity -= velocity / 25;
|
||||||
|
}
|
||||||
|
if (velocity < 0) {
|
||||||
velocity = 0d;
|
velocity = 0d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Double metersCovered = velocity * secondsElapsed;
|
||||||
|
location = getGeoCoordinate(location, heading, metersCovered);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Double getHeading() {
|
public Double getHeading() {
|
||||||
return heading;
|
return heading;
|
||||||
|
|||||||
Reference in New Issue
Block a user