mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Merge branch 'Story62_Creating_Game_Loop' into Merging_GameLoop_with_Broadcast
# Conflicts: # src/main/java/seng302/controllers/StartScreenController.java # src/main/java/seng302/gameServer/ServerListenThread.java # src/main/java/seng302/gameServer/ServerToClientThread.java # src/main/java/seng302/models/Yacht.java
This commit is contained in:
@@ -7,6 +7,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Map;
|
||||
import javafx.scene.paint.Color;
|
||||
import seng302.controllers.RaceViewController;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.models.mark.Mark;
|
||||
import seng302.utilities.GeoPoint;
|
||||
|
||||
@@ -18,6 +19,12 @@ import seng302.utilities.GeoPoint;
|
||||
*/
|
||||
public class Yacht {
|
||||
|
||||
private final Double TURN_STEP = 3.0;
|
||||
|
||||
private Double lastHeading;
|
||||
private Boolean sailIn;
|
||||
|
||||
|
||||
// Used in boat group
|
||||
private Color colour;
|
||||
|
||||
@@ -49,6 +56,18 @@ public class Yacht {
|
||||
private Mark nextMark;
|
||||
|
||||
|
||||
/**
|
||||
* @param location latlon location of the boat stored in a geopoint
|
||||
* @param heading heading of the boat in degrees from 0 to 365 with 0 being north
|
||||
*/
|
||||
public Yacht(GeoPoint location, Double heading) {
|
||||
this.location = location;
|
||||
this.heading = heading;
|
||||
this.velocity = 0.0;
|
||||
this.sailIn = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used in EventTest and RaceTest.
|
||||
*
|
||||
@@ -60,6 +79,7 @@ public class Yacht {
|
||||
this.location = location;
|
||||
this.heading = heading;
|
||||
this.velocity = 0.0;
|
||||
this.sailIn = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,12 +93,13 @@ public class Yacht {
|
||||
this.boatName = boatName;
|
||||
this.velocity = boatVelocity;
|
||||
this.shortName = shortName;
|
||||
this.sourceId = id;
|
||||
this.location = new GeoPoint(0.0, 0.0);
|
||||
this.sourceID = id;
|
||||
this.sailIn = false;
|
||||
}
|
||||
|
||||
|
||||
public Yacht(String boatType, Integer sourceId, String hullID, String shortName,
|
||||
String boatName, String country) {
|
||||
String boatName, String country) {
|
||||
this.boatType = boatType;
|
||||
this.sourceId = sourceId;
|
||||
this.hullID = hullID;
|
||||
@@ -86,6 +107,7 @@ public class Yacht {
|
||||
this.boatName = boatName;
|
||||
this.country = country;
|
||||
this.position = "-";
|
||||
this.sailIn = false;
|
||||
this.location = new GeoPoint(0.0, 0.0);
|
||||
this.heading = 0.0;
|
||||
this.velocity = 0.0;
|
||||
@@ -95,9 +117,11 @@ public class Yacht {
|
||||
* @param timeInterval since last update in milliseconds
|
||||
*/
|
||||
public void update(Long timeInterval) {
|
||||
Double secondsElapsed = timeInterval / 1000000.0;
|
||||
Double metersCovered = velocity * secondsElapsed;
|
||||
location = getGeoCoordinate(location, heading, metersCovered);
|
||||
if (sailIn) {
|
||||
Double secondsElapsed = timeInterval / 1000000.0;
|
||||
Double metersCovered = velocity * secondsElapsed;
|
||||
location = getGeoCoordinate(location, heading, metersCovered);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,6 +149,52 @@ public class Yacht {
|
||||
velocity = polarsFromClosestSpd.get(closest_key);
|
||||
}
|
||||
|
||||
public Double getHeading() {
|
||||
return heading;
|
||||
}
|
||||
|
||||
public void adjustHeading(Double amount) {
|
||||
lastHeading = heading;
|
||||
heading = (heading + amount) % 360.0;
|
||||
}
|
||||
|
||||
public void tackGybe(Double windDirection) {
|
||||
adjustHeading(-2 * ((heading - windDirection) % 360));
|
||||
}
|
||||
|
||||
public void toggleSailIn() {
|
||||
sailIn = !sailIn;
|
||||
}
|
||||
|
||||
public void turnUpwind() {
|
||||
Double normalizedHeading = (heading - GameState.windDirection) % 360;
|
||||
if (normalizedHeading == 0) {
|
||||
if (lastHeading < 180) {
|
||||
adjustHeading(-TURN_STEP);
|
||||
} else {
|
||||
adjustHeading(TURN_STEP);
|
||||
}
|
||||
} else if (normalizedHeading == 180) {
|
||||
if (lastHeading < 180) {
|
||||
adjustHeading(TURN_STEP);
|
||||
} else {
|
||||
adjustHeading(-TURN_STEP);
|
||||
}
|
||||
} else if (normalizedHeading < 180) {
|
||||
adjustHeading(-TURN_STEP);
|
||||
} else {
|
||||
adjustHeading(TURN_STEP);
|
||||
}
|
||||
}
|
||||
|
||||
public void turnDownwind() {
|
||||
if ((heading - GameState.windDirection) % 360 < 180) {
|
||||
adjustHeading(TURN_STEP);
|
||||
} else {
|
||||
adjustHeading(-TURN_STEP);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getBoatType() {
|
||||
return boatType;
|
||||
@@ -249,12 +319,16 @@ public class Yacht {
|
||||
}
|
||||
|
||||
public void setNextMark(Mark nextMark) {
|
||||
this.nextMark = nextMark;
|
||||
}
|
||||
this.nextMark = nextMark;
|
||||
}
|
||||
|
||||
public Mark getNextMark(){
|
||||
return nextMark;
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean getSailIn() {
|
||||
return sailIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
Reference in New Issue
Block a user