Fixed sails out / colliding issue. #story[1297]

main
Joseph Gardner 8 years ago
parent 332722e099
commit 7d789c04bb

@ -36,6 +36,7 @@ public class CollisionCommand extends ObserverCommand {
@Override @Override
public void update(Observable o, Object arg) { public void update(Observable o, Object arg) {
if(GPSCoordinate.calculateDistanceMeters(boat.getPosition(), startingPosition) < distance) { if(GPSCoordinate.calculateDistanceMeters(boat.getPosition(), startingPosition) < distance) {
boat.setVelocityDefault(false);
boat.setPosition(GPSCoordinate.calculateNewPosition(boat.getPosition(), 3, azimuth)); boat.setPosition(GPSCoordinate.calculateNewPosition(boat.getPosition(), 3, azimuth));
} else { } else {
race.deleteObserver(this); race.deleteObserver(this);

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

Loading…
Cancel
Save