mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Added tests, and sails to all clients.
#story[1111]
This commit is contained in:
@@ -62,7 +62,7 @@ public class Yacht {
|
||||
private CompoundMark lastMarkRounded;
|
||||
private Integer positionInt = 0;
|
||||
private Color colour;
|
||||
private Boolean clientSailsIn = false;
|
||||
private Boolean clientSailsIn = true;
|
||||
|
||||
public Yacht(String boatType, Integer sourceId, String hullID, String shortName,
|
||||
String boatName, String country) {
|
||||
@@ -397,6 +397,10 @@ public class Yacht {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
|
||||
public Boolean getClientSailsIn(){
|
||||
return clientSailsIn;
|
||||
}
|
||||
|
||||
public void updateLocation (double lat, double lon, double heading, double velocity) {
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
|
||||
@@ -328,7 +328,7 @@ public class GameView extends Pane {
|
||||
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, sailIn);
|
||||
bo.moveTo(p2d.getX(), p2d.getY(), heading, velocity, sailIn, 95.0);
|
||||
// annotations.get(boat).setLayoutX(p2d.getX());
|
||||
// annotations.get(boat).setLayoutY(p2d.getY());
|
||||
// annotations.get(boat).setLocation(100d, 100d);
|
||||
@@ -576,6 +576,7 @@ public class GameView extends Pane {
|
||||
|
||||
public void setBoatAsPlayer (Yacht playerYacht) {
|
||||
this.playerYacht = playerYacht;
|
||||
this.playerYacht.toggleClientSail();
|
||||
boatObjects.get(playerYacht).setAsPlayer();
|
||||
annotations.get(playerYacht).addAnnotation(
|
||||
"velocity",
|
||||
|
||||
@@ -12,7 +12,6 @@ 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
|
||||
@@ -97,7 +96,16 @@ public class BoatObject extends Group {
|
||||
trail.setCache(true);
|
||||
wake = new Wake(0, -BOAT_HEIGHT);
|
||||
wake.setVisible(true);
|
||||
super.getChildren().addAll(boatPoly);
|
||||
|
||||
sail = new Polygon(0.0,BOAT_HEIGHT / 4,
|
||||
0.0, BOAT_HEIGHT);
|
||||
sailState = 0;
|
||||
sail.setStrokeWidth(2.0);
|
||||
sail.setStroke(Color.BLACK);
|
||||
sail.setFill(Color.TRANSPARENT);
|
||||
sail.setCache(true);
|
||||
super.getChildren().clear();
|
||||
super.getChildren().addAll(boatPoly, sail);
|
||||
}
|
||||
|
||||
public void setFill (Paint value) {
|
||||
@@ -114,23 +122,23 @@ public class BoatObject extends Group {
|
||||
* @param velocity The velocity the boat is moving
|
||||
* @param sailIn
|
||||
*/
|
||||
public void moveTo(double x, double y, double rotation, double velocity, Boolean sailIn) {
|
||||
public void moveTo(double x, double y, double rotation, double velocity, Boolean sailIn, double windDir) {
|
||||
Double dx = Math.abs(boatPoly.getLayoutX() - x);
|
||||
Double dy = Math.abs(boatPoly.getLayoutY() - y);
|
||||
Platform.runLater(() -> {
|
||||
rotateTo(rotation, sailIn);
|
||||
rotateTo(rotation, sailIn, windDir);
|
||||
boatPoly.setLayoutX(x);
|
||||
boatPoly.setLayoutY(y);
|
||||
if (isPlayer && !sailIn) {
|
||||
animateSail();
|
||||
sail.setLayoutX(x);
|
||||
sail.setLayoutY(y);
|
||||
} else if (isPlayer) {
|
||||
if (sailIn) {
|
||||
sail.getPoints().clear();
|
||||
sail.getPoints().addAll(0.0,BOAT_HEIGHT / 4,
|
||||
0.0, BOAT_HEIGHT);
|
||||
sail.setLayoutX(x);
|
||||
sail.setLayoutY(y);
|
||||
} else {
|
||||
animateSail();
|
||||
sail.setLayoutX(x);
|
||||
sail.setLayoutY(y);
|
||||
}
|
||||
wake.setLayoutX(x);
|
||||
wake.setLayoutY(y);
|
||||
@@ -156,11 +164,11 @@ public class BoatObject extends Group {
|
||||
}
|
||||
}
|
||||
|
||||
private void rotateTo(double rotation, boolean sailsIn) {
|
||||
private void rotateTo(double rotation, boolean sailsIn, double windDir) {
|
||||
boatPoly.getTransforms().setAll(new Rotate(rotation));
|
||||
if (isPlayer && sailsIn) {
|
||||
if (sailsIn) {
|
||||
sail.getTransforms().setAll(new Rotate(95.0));
|
||||
} else if (isPlayer){
|
||||
} else {
|
||||
sail.getTransforms().setAll(new Rotate(90.0));
|
||||
}
|
||||
}
|
||||
@@ -309,21 +317,12 @@ public class BoatObject extends Group {
|
||||
boatPoly.setStroke(Color.BLACK);
|
||||
boatPoly.setStrokeWidth(3);
|
||||
isPlayer = true;
|
||||
sail = new Polygon(0.0, BOAT_HEIGHT / 4,
|
||||
0.0, BOAT_HEIGHT);
|
||||
sailState = 0;
|
||||
sail.setStrokeWidth(2.0);
|
||||
sail.setStroke(Color.BLACK);
|
||||
sail.setFill(Color.TRANSPARENT);
|
||||
sail.setCache(true);
|
||||
super.getChildren().clear();
|
||||
super.getChildren().addAll(boatPoly, sail);
|
||||
animateSail();
|
||||
}
|
||||
|
||||
public void setTrajectory(double heading, double velocity) {
|
||||
public void setTrajectory(double heading, double velocity, double windDir) {
|
||||
wake.setRotation(lastHeading - heading, velocity);
|
||||
rotateTo(heading, false);
|
||||
rotateTo(heading, false, windDir);
|
||||
xVelocity = Math.cos(Math.toRadians(heading)) * velocity;
|
||||
yVelocity = Math.sin(Math.toRadians(heading)) * velocity;
|
||||
lastHeading = heading;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package seng302.visualiser.map;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seng302.model.Yacht;
|
||||
import seng302.visualiser.fxObjects.BoatObject;
|
||||
|
||||
/**
|
||||
* Created by kre39 on 6/08/17.
|
||||
*/
|
||||
public class BoatSailAnimationToggleTest {
|
||||
|
||||
private Yacht yacht;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception{
|
||||
yacht = new Yacht("Yacht", 1, "YACHT", "YAC", "Test Yacht", "NZ");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void sailToggleTest() throws Exception {
|
||||
assertFalse(yacht.getClientSailsIn());
|
||||
assertFalse(yacht.getSailIn());
|
||||
yacht.toggleClientSail();
|
||||
assertTrue(yacht.getClientSailsIn());
|
||||
assertFalse(yacht.getSailIn());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user