Fixed sails out / colliding issue. #story[1297]
This commit is contained in:
@@ -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);
|
||||||
} else if (!sailsOut && boat.getCurrentSpeed() > goalVelocity) {
|
if (sailsOut && boat.getCurrentSpeed() < goalVelocity) {
|
||||||
// Apply deceleration to strictly 0 speed
|
boat.setCurrentSpeed(Math.min(goalVelocity, boat.getCurrentSpeed() + acceleration));
|
||||||
if (!boat.isColliding()) boat.setCurrentSpeed(Math.max(0, boat.getCurrentSpeed() - acceleration));
|
} else if (!sailsOut && boat.getCurrentSpeed() > goalVelocity) {
|
||||||
} else {
|
// Apply deceleration to strictly 0 speed
|
||||||
// Release boat from SailsCommand control
|
boat.setCurrentSpeed(Math.max(0, boat.getCurrentSpeed() - acceleration));
|
||||||
if(sailsOut) boat.setVelocityDefault(true);
|
} else {
|
||||||
race.deleteObserver(this);
|
// Release boat from SailsCommand control
|
||||||
|
if (sailsOut) boat.setVelocityDefault(true);
|
||||||
|
race.deleteObserver(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user