mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Adjusted the velocity calculations to allow for Acceleration/Deceleration of the boats, rather than just coming to a complete halt when the sails are pulled in.
#story[986]
This commit is contained in:
@@ -4,8 +4,6 @@ import static seng302.utilities.GeoUtility.getGeoCoordinate;
|
|||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import seng302.client.ClientPacketParser;
|
import seng302.client.ClientPacketParser;
|
||||||
import seng302.controllers.RaceViewController;
|
import seng302.controllers.RaceViewController;
|
||||||
@@ -119,17 +117,28 @@ 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);
|
Double maxBoatSpeed = boatSpeedInKnots / ClientPacketParser.MS_TO_KNOTS * 1000;
|
||||||
velocity = boatSpeedInKnots / ClientPacketParser.MS_TO_KNOTS * 1000;
|
if (sailIn && velocity <= maxBoatSpeed) { // Acceleration
|
||||||
Double metersCovered = velocity * secondsElapsed;
|
if (velocity < maxBoatSpeed) {
|
||||||
location = getGeoCoordinate(location, heading, metersCovered);
|
velocity += maxBoatSpeed / 25;
|
||||||
} else {
|
if (velocity > maxBoatSpeed) {
|
||||||
velocity = 0d;
|
velocity = maxBoatSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else { // Deceleration
|
||||||
|
if (velocity > 0) {
|
||||||
|
velocity = velocity -= maxBoatSpeed / 25;
|
||||||
|
if (velocity < 0) {
|
||||||
|
velocity = 0d;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Double metersCovered = velocity * secondsElapsed;
|
||||||
|
location = getGeoCoordinate(location, heading, metersCovered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user