|
|
|
|
@ -37,15 +37,18 @@ public class SailsCommand extends ObserverCommand {
|
|
|
|
|
public void update(Observable o, Object arg) {
|
|
|
|
|
double acceleration = 0.5;
|
|
|
|
|
|
|
|
|
|
if(sailsOut && boat.getCurrentSpeed() < goalVelocity) {
|
|
|
|
|
if (!boat.isColliding()) boat.setCurrentSpeed(Math.min(goalVelocity, boat.getCurrentSpeed() + acceleration));
|
|
|
|
|
} else if (!sailsOut && boat.getCurrentSpeed() > goalVelocity) {
|
|
|
|
|
// Apply deceleration to strictly 0 speed
|
|
|
|
|
if (!boat.isColliding()) boat.setCurrentSpeed(Math.max(0, boat.getCurrentSpeed() - acceleration));
|
|
|
|
|
} else {
|
|
|
|
|
// Release boat from SailsCommand control
|
|
|
|
|
if(sailsOut) boat.setVelocityDefault(true);
|
|
|
|
|
race.deleteObserver(this);
|
|
|
|
|
if (!boat.isColliding()) {
|
|
|
|
|
boat.setVelocityDefault(false);
|
|
|
|
|
if (sailsOut && boat.getCurrentSpeed() < goalVelocity) {
|
|
|
|
|
boat.setCurrentSpeed(Math.min(goalVelocity, boat.getCurrentSpeed() + acceleration));
|
|
|
|
|
} else if (!sailsOut && boat.getCurrentSpeed() > goalVelocity) {
|
|
|
|
|
// Apply deceleration to strictly 0 speed
|
|
|
|
|
boat.setCurrentSpeed(Math.max(0, boat.getCurrentSpeed() - acceleration));
|
|
|
|
|
} else {
|
|
|
|
|
// Release boat from SailsCommand control
|
|
|
|
|
if (sailsOut) boat.setVelocityDefault(true);
|
|
|
|
|
race.deleteObserver(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|