mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Made the sails work properly by toggling.
Need to remove the unneeded code I added. #story[1111]
This commit is contained in:
@@ -23,9 +23,10 @@ import seng302.model.mark.CompoundMark;
|
||||
*/
|
||||
public class Yacht {
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface YachtLocationListener {
|
||||
void notifyLocation(Yacht yacht, double lat, double lon, double heading, double velocity);
|
||||
void notifyLocation(Yacht yacht, double lat, double lon, double heading, double velocity, boolean sailIn);
|
||||
}
|
||||
|
||||
//BOTH AFAIK
|
||||
@@ -48,7 +49,7 @@ public class Yacht {
|
||||
//SERVER SIDE
|
||||
private final Double TURN_STEP = 5.0;
|
||||
private Double lastHeading;
|
||||
private Boolean sailIn;
|
||||
private Boolean sailIn = false;
|
||||
private GeoPoint location;
|
||||
private Integer boatStatus;
|
||||
private Double velocity;
|
||||
@@ -61,6 +62,7 @@ public class Yacht {
|
||||
private CompoundMark lastMarkRounded;
|
||||
private Integer positionInt = 0;
|
||||
private Color colour;
|
||||
private Boolean clientSailsIn = false;
|
||||
|
||||
public Yacht(String boatType, Integer sourceId, String hullID, String shortName,
|
||||
String boatName, String country) {
|
||||
@@ -70,7 +72,6 @@ public class Yacht {
|
||||
this.shortName = shortName;
|
||||
this.boatName = boatName;
|
||||
this.country = country;
|
||||
this.sailIn = false;
|
||||
this.location = new GeoPoint(57.670341, 11.826856);
|
||||
this.heading = 120.0; //In degrees
|
||||
this.velocity = 0d; //in mms-1
|
||||
@@ -281,6 +282,10 @@ public class Yacht {
|
||||
this.velocityProperty.set(velocity);
|
||||
}
|
||||
|
||||
public void updateSailsInProperty(Boolean clientSails) {
|
||||
this.clientSailsIn = clientSails;
|
||||
}
|
||||
|
||||
public void setMarkRoundingTime(Long markRoundingTime) {
|
||||
this.markRoundTime = markRoundingTime;
|
||||
}
|
||||
@@ -383,6 +388,9 @@ public class Yacht {
|
||||
this.colour = colour;
|
||||
}
|
||||
|
||||
public void toggleClientSail() {
|
||||
clientSailsIn = !clientSailsIn;
|
||||
}
|
||||
|
||||
public Double getVelocity() {
|
||||
return velocity;
|
||||
@@ -399,7 +407,7 @@ public class Yacht {
|
||||
this.velocity = velocity;
|
||||
updateVelocityProperty(velocity);
|
||||
for (YachtLocationListener yll : locationListeners) {
|
||||
yll.notifyLocation(this, lat, lon, heading, velocity);
|
||||
yll.notifyLocation(this, lat, lon, heading, velocity, this.clientSailsIn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -319,6 +319,7 @@ public class GameClient {
|
||||
BoatActionMessage boatActionMessage = new BoatActionMessage(
|
||||
BoatActionType.SAILS_IN);
|
||||
socketThread.sendBoatActionMessage(boatActionMessage);
|
||||
raceView.getGameView().getPlayerYacht().toggleClientSail();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ public class GameView extends Pane {
|
||||
private Double frameRate = 60.0;
|
||||
private int frameTimeIndex = 0;
|
||||
private boolean arrayFilled = false;
|
||||
private Yacht playerYacht;
|
||||
|
||||
private enum ScaleDirection {
|
||||
HORIZONTAL,
|
||||
@@ -324,10 +325,10 @@ public class GameView extends Pane {
|
||||
boatObjectGroup.getChildren().add(newBoat);
|
||||
trails.getChildren().add(newBoat.getTrail());
|
||||
// TODO: 1/08/17 Make this less vile to look at.
|
||||
yacht.addLocationListener((boat, lat, lon, heading, velocity) ->{
|
||||
yacht.addLocationListener((boat, lat, lon, heading, velocity, sailIn) ->{
|
||||
BoatObject bo = boatObjects.get(boat);
|
||||
Point2D p2d = findScaledXY(lat, lon);
|
||||
bo.moveTo(p2d.getX(), p2d.getY(), heading, velocity);
|
||||
bo.moveTo(p2d.getX(), p2d.getY(), heading, velocity, sailIn);
|
||||
// annotations.get(boat).setLayoutX(p2d.getX());
|
||||
// annotations.get(boat).setLayoutY(p2d.getY());
|
||||
// annotations.get(boat).setLocation(100d, 100d);
|
||||
@@ -569,7 +570,12 @@ public class GameView extends Pane {
|
||||
timer.start();
|
||||
}
|
||||
|
||||
public Yacht getPlayerYacht() {
|
||||
return playerYacht;
|
||||
}
|
||||
|
||||
public void setBoatAsPlayer (Yacht playerYacht) {
|
||||
this.playerYacht = playerYacht;
|
||||
boatObjects.get(playerYacht).setAsPlayer();
|
||||
annotations.get(playerYacht).addAnnotation(
|
||||
"velocity",
|
||||
|
||||
@@ -595,4 +595,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
this.courseData = raceData;
|
||||
gameView.updateBorder(raceData.getCourseLimit());
|
||||
}
|
||||
|
||||
public GameView getGameView() {
|
||||
return gameView;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import javafx.scene.shape.Line;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.shape.Polyline;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import seng302.gameServer.GameState;
|
||||
|
||||
/**
|
||||
* BoatGroup is a javafx group that by default contains a graphical objects for representing a 2
|
||||
@@ -30,9 +31,11 @@ public class BoatObject extends Group {
|
||||
private double xVelocity;
|
||||
private double yVelocity;
|
||||
private double lastHeading;
|
||||
private double sailState;
|
||||
//Graphical objects
|
||||
private Polyline trail = new Polyline();
|
||||
private Polygon boatPoly;
|
||||
private Polygon sail;
|
||||
private Wake wake;
|
||||
private Line leftLayLine;
|
||||
private Line rightLayline;
|
||||
@@ -87,14 +90,21 @@ public class BoatObject extends Group {
|
||||
|
||||
// annotationBox = new AnnotationBox();
|
||||
// annotationBox.setFill(colour);
|
||||
|
||||
sail = new Polygon(0.0, BOAT_HEIGHT / 4,
|
||||
0.0, BOAT_HEIGHT);
|
||||
sailState = 0;
|
||||
sail.setStrokeWidth(2.0);
|
||||
sail.setStroke(Color.SILVER);
|
||||
sail.setFill(Color.TRANSPARENT);
|
||||
sail.setCache(true);
|
||||
animateSail();
|
||||
leftLayLine = new Line();
|
||||
rightLayline = new Line();
|
||||
trail.getStrokeDashArray().setAll(5d, 10d);
|
||||
trail.setCache(true);
|
||||
wake = new Wake(0, -BOAT_HEIGHT);
|
||||
wake.setVisible(true);
|
||||
super.getChildren().addAll(boatPoly);//, annotationBox);
|
||||
super.getChildren().addAll(boatPoly, sail);//, annotationBox);
|
||||
}
|
||||
|
||||
public void setFill (Paint value) {
|
||||
@@ -105,19 +115,29 @@ public class BoatObject extends Group {
|
||||
|
||||
/**
|
||||
* Moves the boat and its children annotations to coordinates specified
|
||||
*
|
||||
* @param x The X coordinate to move the boat to
|
||||
* @param x The X coordinate to move the boat to
|
||||
* @param y The Y coordinate to move the boat to
|
||||
* @param rotation The rotation by which the boat moves
|
||||
* @param velocity The velocity the boat is moving
|
||||
* @param sailIn
|
||||
*/
|
||||
public void moveTo(double x, double y, double rotation, double velocity) {
|
||||
public void moveTo(double x, double y, double rotation, double velocity, Boolean sailIn) {
|
||||
Double dx = Math.abs(boatPoly.getLayoutX() - x);
|
||||
Double dy = Math.abs(boatPoly.getLayoutY() - y);
|
||||
Platform.runLater(() -> {
|
||||
rotateTo(rotation);
|
||||
rotateTo(rotation, sailIn);
|
||||
boatPoly.setLayoutX(x);
|
||||
boatPoly.setLayoutY(y);
|
||||
sail.setLayoutX(x);
|
||||
sail.setLayoutY(y);
|
||||
if (!sailIn) {
|
||||
animateSail();
|
||||
} else {
|
||||
sail.getPoints().clear();
|
||||
sail.getPoints().addAll(0.0,BOAT_HEIGHT / 4,
|
||||
0.0, BOAT_HEIGHT);
|
||||
|
||||
}
|
||||
wake.setLayoutX(x);
|
||||
wake.setLayoutY(y);
|
||||
});
|
||||
@@ -142,8 +162,24 @@ public class BoatObject extends Group {
|
||||
}
|
||||
}
|
||||
|
||||
private void rotateTo(double rotation) {
|
||||
private void rotateTo(double rotation, boolean sailsIn) {
|
||||
boatPoly.getTransforms().setAll(new Rotate(rotation));
|
||||
if (sailsIn) {
|
||||
sail.getTransforms().setAll(new Rotate(GameState.getWindDirection() + 95.0));
|
||||
} else {
|
||||
sail.getTransforms().setAll(new Rotate(GameState.getWindDirection()));
|
||||
}
|
||||
}
|
||||
private void animateSail(){
|
||||
Double[] points = new Double[100];
|
||||
for (int i = 0; i < 50; i++) {
|
||||
points[i * 2] = 5 * Math.sin(((Math.PI * i) / 25 + sailState));
|
||||
points[i * 2 + 1] = (BOAT_HEIGHT * i) / 25 + BOAT_HEIGHT / 4;
|
||||
}
|
||||
sailState = sailState + Math.PI / 10;
|
||||
sail.getPoints().clear();
|
||||
sail.getPoints().addAll(points);
|
||||
|
||||
}
|
||||
|
||||
public void updateLocation() {
|
||||
@@ -279,7 +315,7 @@ public class BoatObject extends Group {
|
||||
|
||||
public void setTrajectory(double heading, double velocity) {
|
||||
wake.setRotation(lastHeading - heading, velocity);
|
||||
rotateTo(heading);
|
||||
rotateTo(heading, false);
|
||||
xVelocity = Math.cos(Math.toRadians(heading)) * velocity;
|
||||
yVelocity = Math.sin(Math.toRadians(heading)) * velocity;
|
||||
lastHeading = heading;
|
||||
|
||||
Reference in New Issue
Block a user