mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Wakes still broken. Implemented dashed lines that track the progress of individual boats.
#implement #story[483]
This commit is contained in:
@@ -179,7 +179,10 @@ public class CanvasController {
|
||||
//System.out.println("p.toString() = " + p.toString());
|
||||
double heading = 360.0 / 0xffff * p.getZ();
|
||||
//System.out.println("heading = " + heading);
|
||||
|
||||
raceObject.setDestination(p2d.getX(), p2d.getY(), heading, id);
|
||||
|
||||
//raceObject.setDestination(p2d.getX(), p2d.getY(), id);
|
||||
}
|
||||
StreamParser.boatPositions.remove((long) id);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package seng302.models;
|
||||
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Line;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.transform.Rotate;
|
||||
@@ -24,11 +26,18 @@ public class BoatGroup extends RaceObject{
|
||||
private static final double BOAT_WIDTH = 10d;
|
||||
//Time between sections of race - Should be changed to 200 for actual program.
|
||||
private static double expectedUpdateInterval = 200;
|
||||
private static int WAKE_FRAME_INTERVAL = 80;
|
||||
private static int WAKE_FRAME_INTERVAL = 30;
|
||||
private double framesForNewLine = 0;
|
||||
private Point2D lastPoint;
|
||||
|
||||
private Boat boat;
|
||||
private int wakeCounter = WAKE_FRAME_INTERVAL;
|
||||
private List<Wake> wakes = new ArrayList<>();
|
||||
private List<Line> lines = new ArrayList<>();
|
||||
private Polygon boatPoly;
|
||||
private Polygon wakePoly;
|
||||
private Text teamNameObject;
|
||||
private Text velocityObject;
|
||||
|
||||
public BoatGroup (Boat boat, Color color){
|
||||
this.boat = boat;
|
||||
@@ -41,22 +50,21 @@ public class BoatGroup extends RaceObject{
|
||||
}
|
||||
|
||||
private void initChildren (Color color, double... points) {
|
||||
Polygon boatPoly = new Polygon(points);
|
||||
boatPoly = new Polygon(points);
|
||||
boatPoly.setFill(color);
|
||||
// boatPoly.setLayoutX(0);
|
||||
// boatPoly.setLayoutY(0);
|
||||
// boatPoly.relocate(boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
||||
|
||||
Polygon wake = new Polygon(
|
||||
wakePoly = new Polygon(
|
||||
5.0,0.0,
|
||||
10.0, boat.getVelocity() * VELOCITY_WAKE_RATIO,
|
||||
0.0, boat.getVelocity() * VELOCITY_WAKE_RATIO
|
||||
);
|
||||
wake.setFill(Color.DARKBLUE);
|
||||
wakePoly.setFill(Color.DARKBLUE);
|
||||
|
||||
Text teamNameObject = new Text(boat.getShortName());
|
||||
Text velocityObject = new Text(String.valueOf(boat.getVelocity()));
|
||||
|
||||
boatPoly.setLayoutX(0);
|
||||
boatPoly.setLayoutY(0);
|
||||
boatPoly.relocate(boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
||||
teamNameObject = new Text(boat.getShortName());
|
||||
velocityObject = new Text(String.valueOf(boat.getVelocity()));
|
||||
|
||||
teamNameObject.setX(TEAMNAME_X_OFFSET);
|
||||
teamNameObject.setY(TEAMNAME_Y_OFFSET);
|
||||
@@ -66,7 +74,7 @@ public class BoatGroup extends RaceObject{
|
||||
velocityObject.setY(VELOCITY_Y_OFFSET);
|
||||
velocityObject.relocate(velocityObject.getX(), velocityObject.getY());
|
||||
|
||||
super.getChildren().addAll(boatPoly, teamNameObject, velocityObject);
|
||||
super.getChildren().addAll(wakePoly, boatPoly, teamNameObject, velocityObject);
|
||||
}
|
||||
|
||||
private void initChildren (Color color) {
|
||||
@@ -75,14 +83,21 @@ public class BoatGroup extends RaceObject{
|
||||
BOAT_WIDTH, BOAT_HEIGHT,
|
||||
0.0, BOAT_HEIGHT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the boat and its children annotations from its current coordinates by specified amounts.
|
||||
* @param dx The amount to move the X coordinate by
|
||||
* @param dy The amount to move the Y coordinate by
|
||||
*/
|
||||
public void moveGroupBy(double dx, double dy, double rotation) {
|
||||
super.setLayoutX(super.getLayoutX() + dx);
|
||||
super.setLayoutY(super.getLayoutY() + dy);
|
||||
boatPoly.setLayoutX(boatPoly.getLayoutX() + dx);
|
||||
boatPoly.setLayoutY(boatPoly.getLayoutY() + dy);
|
||||
teamNameObject.setLayoutX(teamNameObject.getLayoutX() + dx);
|
||||
teamNameObject.setLayoutY(teamNameObject.getLayoutY() + dy);
|
||||
velocityObject.setLayoutX(velocityObject.getLayoutX() + dx);
|
||||
velocityObject.setLayoutY(velocityObject.getLayoutY() + dy);
|
||||
wakePoly.setLayoutX(wakePoly.getLayoutX() + dx);
|
||||
wakePoly.setLayoutY(wakePoly.getLayoutY() + dy);
|
||||
rotateTo(currentRotation + rotation);
|
||||
}
|
||||
|
||||
@@ -94,11 +109,18 @@ public class BoatGroup extends RaceObject{
|
||||
public void moveTo (double x, double y, double rotation) {
|
||||
rotateTo(rotation);
|
||||
moveTo(x, y);
|
||||
|
||||
}
|
||||
|
||||
public void moveTo (double x, double y) {
|
||||
super.setLayoutX(x);
|
||||
super.setLayoutY(y);
|
||||
boatPoly.setLayoutX(x);
|
||||
boatPoly.setLayoutY(y);
|
||||
teamNameObject.setLayoutX(x);
|
||||
teamNameObject.setLayoutY(y);
|
||||
velocityObject.setLayoutX(x);
|
||||
velocityObject.setLayoutY(y);
|
||||
wakePoly.setLayoutX(x);
|
||||
wakePoly.setLayoutY(y);
|
||||
}
|
||||
|
||||
public void updatePosition (double timeInterval) {
|
||||
@@ -123,6 +145,8 @@ public class BoatGroup extends RaceObject{
|
||||
}
|
||||
}
|
||||
if (wakeCounter-- == 0) {
|
||||
// if (boat.getShortName().equals("BAR"))
|
||||
// System.out.println("thinking");
|
||||
wakeCounter = WAKE_FRAME_INTERVAL;
|
||||
if (pixelVelocityX > 0 && pixelVelocityY > 0) {
|
||||
// super.getChildren().add(
|
||||
@@ -131,33 +155,37 @@ public class BoatGroup extends RaceObject{
|
||||
// )
|
||||
// );
|
||||
Wake wake = new Wake(
|
||||
super.getLayoutX(),
|
||||
super.getLayoutY(),
|
||||
boatPoly.getLayoutX(),
|
||||
boatPoly.getLayoutY(),
|
||||
pixelVelocityX,
|
||||
pixelVelocityY
|
||||
pixelVelocityY,
|
||||
currentRotation
|
||||
);
|
||||
super.getChildren().add(wake);
|
||||
wakes.add(wake);
|
||||
}
|
||||
|
||||
}
|
||||
if (framesForNewLine == 0) {
|
||||
framesForNewLine = 121;
|
||||
if (lastPoint != null) {
|
||||
Line l = new Line(lastPoint.getX(), lastPoint.getY(), boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
||||
l.getStrokeDashArray().setAll(4d, 4d);
|
||||
lines.add(l);
|
||||
super.getChildren().add(l);
|
||||
}
|
||||
lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
||||
}
|
||||
framesForNewLine -= 1;
|
||||
}
|
||||
|
||||
public void setDestination (double newXValue, double newYValue, double rotation, int... raceIds) {
|
||||
//System.out.println("MADE IT");
|
||||
if (hasRaceId(raceIds)) {
|
||||
this.pixelVelocityX = (newXValue - super.getLayoutX()) / expectedUpdateInterval;
|
||||
this.pixelVelocityY = (newYValue - super.getLayoutY()) / expectedUpdateInterval;
|
||||
this.pixelVelocityX = (newXValue - boatPoly.getLayoutX()) / expectedUpdateInterval;
|
||||
this.pixelVelocityY = (newYValue - boatPoly.getLayoutY()) / expectedUpdateInterval;
|
||||
this.rotationalGoal = rotation;
|
||||
if (Math.abs(rotationalGoal - currentRotation) > 180) {
|
||||
if (rotationalGoal - currentRotation >= 0) {
|
||||
this.rotationalVelocity = ((rotationalGoal - currentRotation) - 360) / expectedUpdateInterval;
|
||||
} else {
|
||||
this.rotationalVelocity = (360 + (rotationalGoal - currentRotation)) / expectedUpdateInterval;
|
||||
}
|
||||
} else {
|
||||
this.rotationalVelocity = (rotationalGoal - currentRotation) / expectedUpdateInterval;
|
||||
}
|
||||
calculateRotationalVelocity();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,15 +194,15 @@ public class BoatGroup extends RaceObject{
|
||||
double rotation = Math.abs(
|
||||
Math.toDegrees(
|
||||
Math.atan(
|
||||
(newYValue - super.getLayoutY()) / (newXValue - super.getLayoutX())
|
||||
(newYValue - boatPoly.getLayoutY()) / (newXValue - boatPoly.getLayoutX())
|
||||
)
|
||||
)
|
||||
);
|
||||
if (super.getLayoutY() >= newYValue && super.getLayoutX() <= newXValue)
|
||||
if (boatPoly.getLayoutY() >= newYValue && boatPoly.getLayoutX() <= newXValue)
|
||||
rotation = 90 - rotation;
|
||||
else if (super.getLayoutY() < newYValue && super.getLayoutX() <= newXValue)
|
||||
else if (boatPoly.getLayoutY() < newYValue && boatPoly.getLayoutX() <= newXValue)
|
||||
rotation = 90 + rotation;
|
||||
else if (super.getLayoutY() >= newYValue && super.getLayoutX() > newXValue)
|
||||
else if (boatPoly.getLayoutY() >= newYValue && boatPoly.getLayoutX() > newXValue)
|
||||
rotation = 270 + rotation;
|
||||
else
|
||||
rotation = 270 - rotation;
|
||||
@@ -183,13 +211,10 @@ public class BoatGroup extends RaceObject{
|
||||
}
|
||||
|
||||
public void rotateTo (double rotation) {
|
||||
Node boatPoly = super.getChildren().get(0);
|
||||
boatPoly.getTransforms().clear();
|
||||
boatPoly.getTransforms().add(new Rotate(rotation, BOAT_WIDTH/2, 0));
|
||||
Node wake = super.getChildren().get(1);
|
||||
wake.getTransforms().clear();
|
||||
wake.getTransforms().add(new Translate(0, BOAT_HEIGHT));
|
||||
wake.getTransforms().add(new Rotate(rotation, BOAT_WIDTH/2, -BOAT_HEIGHT));
|
||||
boatPoly.getTransforms().add(new Rotate(rotation, 0, 0));
|
||||
wakePoly.getTransforms().clear();
|
||||
wakePoly.getTransforms().add(new Rotate(rotation, 0, 0));
|
||||
}
|
||||
|
||||
public void forceRotation () {
|
||||
@@ -197,8 +222,13 @@ public class BoatGroup extends RaceObject{
|
||||
}
|
||||
|
||||
public void toggleAnnotations () {
|
||||
for (Node node : super.getChildren().subList(1, super.getChildren().size())) {
|
||||
node.setVisible(false);
|
||||
teamNameObject.setVisible(!teamNameObject.isVisible());
|
||||
velocityObject.setVisible(!velocityObject.isVisible());
|
||||
for (Wake wake : wakes) {
|
||||
wake.setVisible(!wake.isVisible());
|
||||
}
|
||||
for (Line line : lines) {
|
||||
line.setVisible(!line.isVisible());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import javafx.scene.Group;
|
||||
public abstract class RaceObject extends Group {
|
||||
|
||||
//Time between sections of race - Should be changed to 200 for actual program.
|
||||
protected static double expectedUpdateInterval = 2000;
|
||||
protected static double expectedUpdateInterval = 200;
|
||||
|
||||
protected double rotationalGoal;
|
||||
protected double currentRotation;
|
||||
@@ -33,6 +33,18 @@ public abstract class RaceObject extends Group {
|
||||
RaceObject.expectedUpdateInterval = expectedUpdateInterval;
|
||||
}
|
||||
|
||||
protected void calculateRotationalVelocity () {
|
||||
if (Math.abs(rotationalGoal - currentRotation) > 180) {
|
||||
if (rotationalGoal - currentRotation >= 0) {
|
||||
this.rotationalVelocity = ((rotationalGoal - currentRotation) - 360) / expectedUpdateInterval;
|
||||
} else {
|
||||
this.rotationalVelocity = (360 + (rotationalGoal - currentRotation)) / expectedUpdateInterval;
|
||||
}
|
||||
} else {
|
||||
this.rotationalVelocity = (rotationalGoal - currentRotation) / expectedUpdateInterval;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void setDestination (double x, double y, double rotation, int... raceIds);
|
||||
|
||||
public abstract void setDestination (double x, double y, int... raceIds);
|
||||
|
||||
@@ -3,6 +3,7 @@ package seng302.models;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Arc;
|
||||
import javafx.scene.shape.ArcType;
|
||||
import javafx.scene.transform.Rotate;
|
||||
|
||||
/**
|
||||
* Created by CJIRWIN on 27/04/2017.
|
||||
@@ -10,36 +11,40 @@ import javafx.scene.shape.ArcType;
|
||||
class Wake extends Arc {
|
||||
|
||||
private static int VELOCITY_SCALE_FACTOR = 3;
|
||||
private static int MAX_LIFESPAN = 420;
|
||||
private static int MAX_LIFESPAN = 210;
|
||||
private static double LIFESPAN_PER_FRAME = 1.0 / MAX_LIFESPAN;
|
||||
//private static double LENGTH_PER_FRAME = 120 / MAX_LIFESPAN;
|
||||
private static double LENGTH_PER_FRAME = 0.08;
|
||||
private static double LENGTH_PER_FRAME = 0.25;
|
||||
|
||||
private double velocityX;
|
||||
private double velocityY;
|
||||
private double opacity;
|
||||
private int lifespan = MAX_LIFESPAN;
|
||||
|
||||
Wake (double startingX, double startingY, double velocityX, double velocityY) {
|
||||
super(0, 0, 20, 30, 180, 0);
|
||||
Wake (double startingX, double startingY, double velocityX, double velocityY, double rotation) {
|
||||
super(startingX + 20, startingY + 30, 20, 30, 180, 0);
|
||||
//super.setFill(Color.BLUE);
|
||||
super.setStroke(Color.BLUE);
|
||||
super.setStroke(Color.DEEPSKYBLUE);
|
||||
super.setType(ArcType.OPEN);
|
||||
super.setFill(new Color(0, 0, 0 ,0));
|
||||
super.setStrokeWidth(2.0);
|
||||
this.velocityX = -velocityX / 2;
|
||||
this.velocityY = -velocityY / 2;
|
||||
super.getTransforms().add(new Rotate(rotation - 270, startingX + 20, startingY + 20));
|
||||
// this.velocityX = -velocityX;
|
||||
// this.velocityY = -velocityY;
|
||||
this.velocityX = 0;
|
||||
this.velocityY = 0;
|
||||
}
|
||||
|
||||
boolean updatePosition (double timeInterval) {
|
||||
lifespan--;
|
||||
//super.setOpacity(LIFESPAN_PER_FRAME * lifespan * super.getOpacity());
|
||||
opacity = LIFESPAN_PER_FRAME * lifespan * opacity;
|
||||
super.setFill(new Color(0.0f, 0.0f, 1.0f, opacity));
|
||||
//opacity = LIFESPAN_PER_FRAME * lifespan * opacity;
|
||||
//super.setFill(new Color(0.0f, 0.0f, 1.0f, opacity));
|
||||
super.setLayoutX(super.getLayoutX() + velocityX * timeInterval);
|
||||
super.setLayoutY(super.getLayoutY() + velocityY * timeInterval);
|
||||
super.setStartAngle(super.getStartAngle() - LENGTH_PER_FRAME);
|
||||
super.setLength(super.getLength() + LENGTH_PER_FRAME * 2);
|
||||
return lifespan == 0;
|
||||
return lifespan < 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -114,15 +114,7 @@ public class MarkGroup extends RaceObject {
|
||||
public void setDestination (double x, double y, double rotation, int... raceIds) {
|
||||
setDestination(x, y, raceIds);
|
||||
this.rotationalGoal = rotation;
|
||||
if (Math.abs(rotationalGoal - currentRotation) > 180) {
|
||||
if (rotationalGoal - currentRotation >= 0) {
|
||||
this.rotationalVelocity = ((rotationalGoal - currentRotation) - 360) / expectedUpdateInterval;
|
||||
} else {
|
||||
this.rotationalVelocity = (360 + (rotationalGoal - currentRotation)) / expectedUpdateInterval;
|
||||
}
|
||||
} else {
|
||||
this.rotationalVelocity = (rotationalGoal - currentRotation) / expectedUpdateInterval;
|
||||
}
|
||||
calculateRotationalVelocity();
|
||||
}
|
||||
|
||||
public void setDestination (double x, double y, int... raceIds) {
|
||||
|
||||
@@ -21,7 +21,7 @@ public class StreamPacket {
|
||||
//switch the packet type to deal with what ever specific packet you want to deal with
|
||||
if (this.type == PacketType.XML_MESSAGE){
|
||||
//System.out.println("--------");
|
||||
//System.out.println(new String(payload));
|
||||
System.out.println(new String(payload));
|
||||
StreamParser.parsePacket(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ public class StreamParser extends Thread{
|
||||
long lon = bytesToLong(lonBytes);
|
||||
long heading = bytesToLong(headingBytes);
|
||||
|
||||
if ((int)deviceType == 1){
|
||||
if ((int)deviceType == 1 || (int)deviceType == 4){
|
||||
// System.out.println("boatId = " + boatId);
|
||||
// System.out.println("deviceType = " + (long)deviceType);
|
||||
// System.out.println("seq = " + seq);
|
||||
|
||||
Reference in New Issue
Block a user