Updated initialise boat function so it can now initialise boats with distance apart in meters.

Created a second prototype function which is more testable compared to the initial design. New function takes in parameters (starting marks, yacht starting position, yacht) and initialise yacht correctly with position.

#story[1117]
This commit is contained in:
Zhi You Tan
2017-08-06 21:16:14 +12:00
parent 81c2a8e0fd
commit a470cb66a2
3 changed files with 93 additions and 22 deletions
@@ -187,24 +187,21 @@ public class MainServerThread extends Observable implements Runnable, ClientConn
GeoPoint midpoint = GeoUtility.getGeoCoordinate(startMark1, perpendicularAngle, length / 2);
// Setting each boats position side by side
double distanceApart = 0.0005; // magic number for boat spawn distance apart
double DISTANCEFACTOR = 50.0; // distance apart in meters
int boatIndex = 0;
int boatSpawnDirection = -1; // positive for left and negative for right
for (Yacht yacht : GameState.getYachts().values()) {
Double x =
midpoint.getLat() + boatSpawnDirection * boatIndex * Math.sin(perpendicularAngle)
* distanceApart;
Double y =
midpoint.getLng() + boatSpawnDirection * boatIndex * Math.cos(perpendicularAngle)
* distanceApart;
yacht.setLocation(new GeoPoint(x, y));
int distanceApart = boatIndex / 2;
if (boatSpawnDirection == -1) {
boatSpawnDirection = 1;
boatIndex++;
} else {
boatSpawnDirection = -1;
if (boatIndex % 2 == 1 && boatIndex != 0) {
distanceApart++;
distanceApart *= -1;
}
GeoPoint spawnMark = GeoUtility
.getGeoCoordinate(midpoint, perpendicularAngle, distanceApart * DISTANCEFACTOR);
yacht.setLocation(spawnMark);
boatIndex++;
}
}
}