Working idle sail animation.

Need to work on getting sails to toggle properly. Have the 2 animations almost working but unable to switch between the two.

#story[1111]
This commit is contained in:
Kusal Ekanayake
2017-08-03 14:50:56 +12:00
parent bbf494e9a1
commit eb83e9dcc5
3 changed files with 46 additions and 3 deletions
@@ -97,7 +97,9 @@ public class LobbyController implements Initializable, Observer{
.addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl)));
} catch (javafx.fxml.LoadException e) {
System.out.println("[Controller] FXML load exception");
e.printStackTrace();
} catch (IOException e) {
System.out.println("[Controller] IO exception");
} catch (NullPointerException e) {
// System.out.println("[Controller] Null Pointer Exception");
+40 -2
View File
@@ -11,6 +11,8 @@ import javafx.scene.shape.Line;
import javafx.scene.shape.Polygon;
import javafx.scene.transform.Rotate;
import seng302.client.ClientPacketParser;
import seng302.gameServer.GameStages;
import seng302.gameServer.GameState;
import seng302.models.Yacht;
import seng302.utilities.GeoUtility;
import seng302.controllers.CanvasController;
@@ -43,6 +45,7 @@ public class BoatGroup extends Group {
private Group lineGroup = new Group();
private Polygon boatPoly;
private Wake wake;
private Polygon sail;
private Line leftLayLine;
private Line rightLayline;
private Double distanceTravelled = 0.0;
@@ -52,6 +55,7 @@ public class BoatGroup extends Group {
private Color color;
private Boolean isSelected = true; //All boats are initialised as selected\
private boolean isPlayer = false;
private Double sailState = 0.0;
/**
* Creates a BoatGroup with the default triangular boat polygon.
@@ -105,14 +109,32 @@ public class BoatGroup extends Group {
boatPoly.setCache(true);
boatPoly.setCacheHint(CacheHint.SPEED);
boatAnnotations = new BoatAnnotations(boat, this.color);
sail = new Polygon(0.0,BOAT_HEIGHT / 4,
0.0, BOAT_HEIGHT);
animateSail();
sail.setStrokeWidth(2.0);
sail.setStroke(Color.SILVER);
leftLayLine = new Line();
rightLayline = new Line();
wake = new Wake(0, -BOAT_HEIGHT);
super.getChildren().addAll(boatPoly, boatAnnotations);
super.getChildren().addAll(boatPoly, boatAnnotations, sail);
}
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) / 50 + BOAT_HEIGHT / 4;
}
sailState = sailState + Math.PI / 25;
sail.getPoints().clear();
sail.getPoints().addAll(points);
}
/**
* Creates the javafx objects that will be the in the group by default.
*
@@ -154,6 +176,16 @@ public class BoatGroup extends Group {
boatPoly.setLayoutY(y);
boatAnnotations.setLayoutX(x);
boatAnnotations.setLayoutY(y);
sail.setLayoutX(x);
sail.setLayoutY(y);
if (!boat.getSailIn()) {
animateSail();
} else {
sail.getPoints().clear();
sail.getPoints().addAll(0.0,BOAT_HEIGHT / 4,
0.0, BOAT_HEIGHT);
}
wake.setLayoutX(x);
wake.setLayoutY(y);
wake.rotate(rotation);
@@ -161,6 +193,12 @@ public class BoatGroup extends Group {
private void rotateTo(double rotation) {
boatPoly.getTransforms().setAll(new Rotate(rotation));
//TODO kre39 - Make the sails out angle depend on the facing of the boat
if (!boat.getSailIn()) {
sail.getTransforms().setAll(new Rotate(GameState.getWindDirection() + 95.0));
} else {
sail.getTransforms().setAll(new Rotate(GameState.getWindDirection()));
}
}
/**
+4 -1
View File
@@ -124,6 +124,7 @@ public class Yacht {
Double trueWindAngle = Math.abs(GameState.getWindDirection() - heading);
Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, trueWindAngle);
Double maxBoatSpeed = boatSpeedInKnots / ClientPacketParser.MS_TO_KNOTS * 1000;
System.out.println("sailIn = " + sailIn);
if (sailIn && velocity <= maxBoatSpeed && maxBoatSpeed != 0d) {
if (velocity < maxBoatSpeed) {
@@ -170,7 +171,8 @@ public class Yacht {
}
public void toggleSailIn() {
sailIn = !sailIn;
this.sailIn = !sailIn;
System.out.println("sailIn = " + sailIn);
}
public void turnUpwind() {
@@ -389,6 +391,7 @@ public class Yacht {
}
public Boolean getSailIn() {
System.out.println("sailIn = " + sailIn);
return sailIn;
}