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 CompoundMark lastMarkRounded;
|
||||||
private Integer positionInt = 0;
|
private Integer positionInt = 0;
|
||||||
private Color colour;
|
private Color colour;
|
||||||
private Boolean clientSailsIn = false;
|
private Boolean clientSailsIn = true;
|
||||||
|
|
||||||
public Yacht(String boatType, Integer sourceId, String hullID, String shortName,
|
public Yacht(String boatType, Integer sourceId, String hullID, String shortName,
|
||||||
String boatName, String country) {
|
String boatName, String country) {
|
||||||
@@ -397,6 +397,10 @@ public class Yacht {
|
|||||||
this.velocity = velocity;
|
this.velocity = velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean getClientSailsIn(){
|
||||||
|
return clientSailsIn;
|
||||||
|
}
|
||||||
|
|
||||||
public void updateLocation (double lat, double lon, double heading, double velocity) {
|
public void updateLocation (double lat, double lon, double heading, double velocity) {
|
||||||
this.lat = lat;
|
this.lat = lat;
|
||||||
this.lon = lon;
|
this.lon = lon;
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ public class GameView extends Pane {
|
|||||||
yacht.addLocationListener((boat, lat, lon, heading, velocity, sailIn) ->{
|
yacht.addLocationListener((boat, lat, lon, heading, velocity, sailIn) ->{
|
||||||
BoatObject bo = boatObjects.get(boat);
|
BoatObject bo = boatObjects.get(boat);
|
||||||
Point2D p2d = findScaledXY(lat, lon);
|
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).setLayoutX(p2d.getX());
|
||||||
// annotations.get(boat).setLayoutY(p2d.getY());
|
// annotations.get(boat).setLayoutY(p2d.getY());
|
||||||
// annotations.get(boat).setLocation(100d, 100d);
|
// annotations.get(boat).setLocation(100d, 100d);
|
||||||
@@ -576,6 +576,7 @@ public class GameView extends Pane {
|
|||||||
|
|
||||||
public void setBoatAsPlayer (Yacht playerYacht) {
|
public void setBoatAsPlayer (Yacht playerYacht) {
|
||||||
this.playerYacht = playerYacht;
|
this.playerYacht = playerYacht;
|
||||||
|
this.playerYacht.toggleClientSail();
|
||||||
boatObjects.get(playerYacht).setAsPlayer();
|
boatObjects.get(playerYacht).setAsPlayer();
|
||||||
annotations.get(playerYacht).addAnnotation(
|
annotations.get(playerYacht).addAnnotation(
|
||||||
"velocity",
|
"velocity",
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import javafx.scene.shape.Line;
|
|||||||
import javafx.scene.shape.Polygon;
|
import javafx.scene.shape.Polygon;
|
||||||
import javafx.scene.shape.Polyline;
|
import javafx.scene.shape.Polyline;
|
||||||
import javafx.scene.transform.Rotate;
|
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
|
* 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);
|
trail.setCache(true);
|
||||||
wake = new Wake(0, -BOAT_HEIGHT);
|
wake = new Wake(0, -BOAT_HEIGHT);
|
||||||
wake.setVisible(true);
|
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) {
|
public void setFill (Paint value) {
|
||||||
@@ -114,23 +122,23 @@ public class BoatObject extends Group {
|
|||||||
* @param velocity The velocity the boat is moving
|
* @param velocity The velocity the boat is moving
|
||||||
* @param sailIn
|
* @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 dx = Math.abs(boatPoly.getLayoutX() - x);
|
||||||
Double dy = Math.abs(boatPoly.getLayoutY() - y);
|
Double dy = Math.abs(boatPoly.getLayoutY() - y);
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
rotateTo(rotation, sailIn);
|
rotateTo(rotation, sailIn, windDir);
|
||||||
boatPoly.setLayoutX(x);
|
boatPoly.setLayoutX(x);
|
||||||
boatPoly.setLayoutY(y);
|
boatPoly.setLayoutY(y);
|
||||||
if (isPlayer && !sailIn) {
|
if (sailIn) {
|
||||||
animateSail();
|
|
||||||
sail.setLayoutX(x);
|
|
||||||
sail.setLayoutY(y);
|
|
||||||
} else if (isPlayer) {
|
|
||||||
sail.getPoints().clear();
|
sail.getPoints().clear();
|
||||||
sail.getPoints().addAll(0.0,BOAT_HEIGHT / 4,
|
sail.getPoints().addAll(0.0,BOAT_HEIGHT / 4,
|
||||||
0.0, BOAT_HEIGHT);
|
0.0, BOAT_HEIGHT);
|
||||||
sail.setLayoutX(x);
|
sail.setLayoutX(x);
|
||||||
sail.setLayoutY(y);
|
sail.setLayoutY(y);
|
||||||
|
} else {
|
||||||
|
animateSail();
|
||||||
|
sail.setLayoutX(x);
|
||||||
|
sail.setLayoutY(y);
|
||||||
}
|
}
|
||||||
wake.setLayoutX(x);
|
wake.setLayoutX(x);
|
||||||
wake.setLayoutY(y);
|
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));
|
boatPoly.getTransforms().setAll(new Rotate(rotation));
|
||||||
if (isPlayer && sailsIn) {
|
if (sailsIn) {
|
||||||
sail.getTransforms().setAll(new Rotate(95.0));
|
sail.getTransforms().setAll(new Rotate(95.0));
|
||||||
} else if (isPlayer){
|
} else {
|
||||||
sail.getTransforms().setAll(new Rotate(90.0));
|
sail.getTransforms().setAll(new Rotate(90.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -309,21 +317,12 @@ public class BoatObject extends Group {
|
|||||||
boatPoly.setStroke(Color.BLACK);
|
boatPoly.setStroke(Color.BLACK);
|
||||||
boatPoly.setStrokeWidth(3);
|
boatPoly.setStrokeWidth(3);
|
||||||
isPlayer = true;
|
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();
|
animateSail();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTrajectory(double heading, double velocity) {
|
public void setTrajectory(double heading, double velocity, double windDir) {
|
||||||
wake.setRotation(lastHeading - heading, velocity);
|
wake.setRotation(lastHeading - heading, velocity);
|
||||||
rotateTo(heading, false);
|
rotateTo(heading, false, windDir);
|
||||||
xVelocity = Math.cos(Math.toRadians(heading)) * velocity;
|
xVelocity = Math.cos(Math.toRadians(heading)) * velocity;
|
||||||
yVelocity = Math.sin(Math.toRadians(heading)) * velocity;
|
yVelocity = Math.sin(Math.toRadians(heading)) * velocity;
|
||||||
lastHeading = heading;
|
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