mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Added abstract class for all javafx object that a displayed during race. Began refactoring of mark implementation to be a subclass of the aforementioned abstract class.
This commit is contained in:
@@ -173,7 +173,7 @@ public class CanvasController {
|
|||||||
if (p != null) {
|
if (p != null) {
|
||||||
Point2D p2d = latLonToXY(p.getX(), p.getY());
|
Point2D p2d = latLonToXY(p.getX(), p.getY());
|
||||||
//System.out.println("p2d = " + p2d);
|
//System.out.println("p2d = " + p2d);
|
||||||
if (!boatGroup.getBoat().isSamePos(p2d)) {
|
if (!boatGroup.isSamePos(p2d)) {
|
||||||
//System.out.println("p.toString() = " + p.toString());
|
//System.out.println("p.toString() = " + p.toString());
|
||||||
double heading = 360.0 / 0xffff * p.getZ();
|
double heading = 360.0 / 0xffff * p.getZ();
|
||||||
//System.out.println("heading = " + heading);
|
//System.out.println("heading = " + heading);
|
||||||
@@ -288,7 +288,7 @@ public class CanvasController {
|
|||||||
|
|
||||||
for (Boat boat : boats) {
|
for (Boat boat : boats) {
|
||||||
BoatGroup boatGroup = new BoatGroup(boat, Colors.getColor());
|
BoatGroup boatGroup = new BoatGroup(boat, Colors.getColor());
|
||||||
boatGroup.moveBoatTo(startingX, startingY, 0d);
|
boatGroup.moveTo(startingX, startingY, 0d);
|
||||||
boatGroup.setDestination(firstMarkX, firstMarkY);
|
boatGroup.setDestination(firstMarkX, firstMarkY);
|
||||||
boatGroup.forceRotation();
|
boatGroup.forceRotation();
|
||||||
group.getChildren().add(boatGroup);
|
group.getChildren().add(boatGroup);
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ public class Boat {
|
|||||||
private int markLastPast;
|
private int markLastPast;
|
||||||
private String shortName;
|
private String shortName;
|
||||||
private int id;
|
private int id;
|
||||||
private Point2D currentPos;
|
|
||||||
|
|
||||||
public Boat(String teamName) {
|
public Boat(String teamName) {
|
||||||
this.teamName = teamName;
|
this.teamName = teamName;
|
||||||
@@ -29,17 +28,8 @@ public class Boat {
|
|||||||
this.lat = 0.0;
|
this.lat = 0.0;
|
||||||
this.lon = 0.0;
|
this.lon = 0.0;
|
||||||
this.shortName = "";
|
this.shortName = "";
|
||||||
currentPos = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSamePos(Point2D newPos){
|
|
||||||
if(newPos.equals(currentPos)){
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
currentPos = newPos;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a boat in the race.
|
* Represents a boat in the race.
|
||||||
@@ -53,8 +43,6 @@ public class Boat {
|
|||||||
this.velocity = boatVelocity;
|
this.velocity = boatVelocity;
|
||||||
this.shortName = shortName;
|
this.shortName = shortName;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
currentPos = null;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package seng302.models;
|
package seng302.models;
|
||||||
|
|
||||||
import javafx.scene.Group;
|
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Polygon;
|
import javafx.scene.shape.Polygon;
|
||||||
@@ -11,7 +10,7 @@ import javafx.scene.transform.Translate;
|
|||||||
/**
|
/**
|
||||||
* Created by CJIRWIN on 25/04/2017.
|
* Created by CJIRWIN on 25/04/2017.
|
||||||
*/
|
*/
|
||||||
public class BoatGroup extends Group{
|
public class BoatGroup extends RaceObject{
|
||||||
|
|
||||||
private static final double TEAMNAME_X_OFFSET = 15d;
|
private static final double TEAMNAME_X_OFFSET = 15d;
|
||||||
private static final double TEAMNAME_Y_OFFSET = -20d;
|
private static final double TEAMNAME_Y_OFFSET = -20d;
|
||||||
@@ -25,21 +24,13 @@ public class BoatGroup extends Group{
|
|||||||
|
|
||||||
private Boat boat;
|
private Boat boat;
|
||||||
|
|
||||||
private double rotationalGoal;
|
|
||||||
private double currentRotation;
|
|
||||||
private double rotationalVelocity;
|
|
||||||
private double pixelVelocityX;
|
|
||||||
private double pixelVelocityY;
|
|
||||||
|
|
||||||
public BoatGroup (Boat boat, Color color){
|
public BoatGroup (Boat boat, Color color){
|
||||||
super();
|
|
||||||
this.boat = boat;
|
this.boat = boat;
|
||||||
initChildren(color);
|
initChildren(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BoatGroup (Boat boat, Color color, double... points)
|
public BoatGroup (Boat boat, Color color, double... points)
|
||||||
{
|
{
|
||||||
super();
|
|
||||||
initChildren(color, points);
|
initChildren(color, points);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +78,7 @@ public class BoatGroup extends Group{
|
|||||||
* @param dx The amount to move the X coordinate by
|
* @param dx The amount to move the X coordinate by
|
||||||
* @param dy The amount to move the Y coordinate by
|
* @param dy The amount to move the Y coordinate by
|
||||||
*/
|
*/
|
||||||
void moveBy(Double dx, Double dy, Double rotation) {
|
void moveBy(double dx, double dy, double rotation) {
|
||||||
super.setLayoutX(super.getLayoutX() + dx);
|
super.setLayoutX(super.getLayoutX() + dx);
|
||||||
super.setLayoutY(super.getLayoutY() + dy);
|
super.setLayoutY(super.getLayoutY() + dy);
|
||||||
rotateBoat(rotation);
|
rotateBoat(rotation);
|
||||||
@@ -98,11 +89,15 @@ public class BoatGroup extends Group{
|
|||||||
* @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 y The Y coordinate to move the boat to
|
||||||
*/
|
*/
|
||||||
public void moveBoatTo(Double x, Double y, Double rotation) {
|
public void moveTo (double x, double y, double rotation) {
|
||||||
|
super.currentRotation = 0;
|
||||||
|
rotateBoat(rotation);
|
||||||
|
moveTo(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveTo (double x, double y) {
|
||||||
super.setLayoutX(x);
|
super.setLayoutX(x);
|
||||||
super.setLayoutY(y);
|
super.setLayoutY(y);
|
||||||
currentRotation = 0;
|
|
||||||
rotateBoat(rotation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePosition (double timeInterval) {
|
public void updatePosition (double timeInterval) {
|
||||||
@@ -202,7 +197,7 @@ public class BoatGroup extends Group{
|
|||||||
rotateBoat (rotationalGoal - currentRotation);
|
rotateBoat (rotationalGoal - currentRotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toogleAnnotations () {
|
public void toggleAnnotations () {
|
||||||
super.getChildren().get(1).setVisible(false);
|
super.getChildren().get(1).setVisible(false);
|
||||||
super.getChildren().get(2).setVisible(false);
|
super.getChildren().get(2).setVisible(false);
|
||||||
super.getChildren().get(3).setVisible(false);
|
super.getChildren().get(3).setVisible(false);
|
||||||
@@ -211,4 +206,12 @@ public class BoatGroup extends Group{
|
|||||||
public Boat getBoat() {
|
public Boat getBoat() {
|
||||||
return boat;
|
return boat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasRaceId (int... raceIds) {
|
||||||
|
for (int id : raceIds) {
|
||||||
|
if (id == boat.getId())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package seng302.models;
|
||||||
|
|
||||||
|
import javafx.geometry.Point2D;
|
||||||
|
import javafx.scene.Group;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by CJIRWIN on 26/04/2017.
|
||||||
|
*/
|
||||||
|
public abstract class RaceObject extends Group {
|
||||||
|
|
||||||
|
double rotationalGoal;
|
||||||
|
double currentRotation;
|
||||||
|
double rotationalVelocity;
|
||||||
|
double pixelVelocityX;
|
||||||
|
double pixelVelocityY;
|
||||||
|
|
||||||
|
public boolean isSamePos (Point2D point) {
|
||||||
|
return point.getX() == super.getLayoutX() && point.getY() == super.getLayoutY();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point2D getPosition () {
|
||||||
|
return new Point2D(super.getLayoutX(), getLayoutY());
|
||||||
|
}
|
||||||
|
public abstract void setDestination (double x, double y, double rotation);
|
||||||
|
public abstract void setDestination (double x, double y);
|
||||||
|
public abstract void updatePosition (double timeInterval);
|
||||||
|
public abstract void moveTo (double x, double y, double rotation);
|
||||||
|
public abstract void moveTo (double x, double y);
|
||||||
|
public abstract boolean hasRaceId (int... raceIds);
|
||||||
|
public abstract void toggleAnnotations ();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ public abstract class Mark {
|
|||||||
private MarkType markType;
|
private MarkType markType;
|
||||||
private double latitude;
|
private double latitude;
|
||||||
private double longitude;
|
private double longitude;
|
||||||
|
private int id;
|
||||||
Integer xValue;
|
Integer xValue;
|
||||||
Integer yValue;
|
Integer yValue;
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ public abstract class Mark {
|
|||||||
public Mark (String name, MarkType markType) {
|
public Mark (String name, MarkType markType) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.markType = markType;
|
this.markType = markType;
|
||||||
|
id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mark(String name, MarkType markType, double latitude, double longitude) {
|
public Mark(String name, MarkType markType, double latitude, double longitude) {
|
||||||
@@ -28,6 +30,7 @@ public abstract class Mark {
|
|||||||
this.markType = markType;
|
this.markType = markType;
|
||||||
this.latitude = latitude;
|
this.latitude = latitude;
|
||||||
this.longitude = longitude;
|
this.longitude = longitude;
|
||||||
|
id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,4 +143,12 @@ public abstract class Mark {
|
|||||||
this.yValue = y;
|
this.yValue = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package seng302.models.mark;
|
||||||
|
|
||||||
|
import javafx.geometry.Point2D;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.scene.shape.Circle;
|
||||||
|
import javafx.scene.shape.Line;
|
||||||
|
import javafx.scene.transform.Rotate;
|
||||||
|
import seng302.models.RaceObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by CJIRWIN on 26/04/2017.
|
||||||
|
*/
|
||||||
|
public class MarkGroup extends RaceObject {
|
||||||
|
|
||||||
|
private static int MARK_RADIUS = 5;
|
||||||
|
|
||||||
|
private Mark mark;
|
||||||
|
private double pixelVelocityXM1;
|
||||||
|
private double pixelVelocityYM1;
|
||||||
|
private double pixelVelocityXM2;
|
||||||
|
private double pixelVelocityYM3;
|
||||||
|
|
||||||
|
|
||||||
|
public MarkGroup (Mark mark, Point2D... points) {
|
||||||
|
Color color = Color.BLACK;
|
||||||
|
if (mark.getName().equals("Start")){
|
||||||
|
color = Color.GREEN;
|
||||||
|
} else if (mark.getName().equals("Finish")){
|
||||||
|
color = Color.RED;
|
||||||
|
}
|
||||||
|
if (mark.getMarkType() == MarkType.SINGLE_MARK) {
|
||||||
|
super.getChildren().add(new Circle(0, 0, MARK_RADIUS, color));
|
||||||
|
} else {
|
||||||
|
super.getChildren().add(new Circle(0, 0, MARK_RADIUS, color));
|
||||||
|
super.getChildren().add(
|
||||||
|
new Circle(
|
||||||
|
points[1].getX() - points[0].getX(),
|
||||||
|
points[1].getY() - points[0].getY(),
|
||||||
|
MARK_RADIUS,
|
||||||
|
color
|
||||||
|
)
|
||||||
|
);
|
||||||
|
Line line = new Line(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
points[1].getX() - points[0].getX(),
|
||||||
|
points[1].getY() - points[0].getY()
|
||||||
|
);
|
||||||
|
line.setStrokeWidth(2);
|
||||||
|
if (mark.getMarkType() == MarkType.OPEN_GATE) {
|
||||||
|
line.getStrokeDashArray().addAll(3d, 5d);
|
||||||
|
}
|
||||||
|
super.getChildren().add(line);
|
||||||
|
}
|
||||||
|
this.mark = mark;
|
||||||
|
moveTo(points[0].getX(), points[0].getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDestination (double x, double y, double rotation) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDestination (double x, double y) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMarkDestination (int markId, double x, double y) {
|
||||||
|
|
||||||
|
}
|
||||||
|
public void updatePosition (double timeInterval) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveTo (double x, double y, double rotation) {
|
||||||
|
moveTo(x, y);
|
||||||
|
super.getTransforms().clear();
|
||||||
|
super.getTransforms().add(
|
||||||
|
new Rotate(
|
||||||
|
rotation,
|
||||||
|
super.getChildren().get(1).getLayoutX() - super.getChildren().get(0).getLayoutX(),
|
||||||
|
super.getChildren().get(1).getLayoutY() - super.getChildren().get(0).getLayoutY()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveTo (double x, double y) {
|
||||||
|
super.setLayoutX(x);
|
||||||
|
super.setLayoutY(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasRaceId (int... raceIds) {
|
||||||
|
for (int id : raceIds) {
|
||||||
|
if (id == mark.getId())
|
||||||
|
return true;
|
||||||
|
if (mark.getMarkType() != MarkType.SINGLE_MARK) {
|
||||||
|
if (id == ((GateMark) mark).getSingleMark1().getId() || id == ((GateMark) mark).getSingleMark2().getId())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public void toggleAnnotations () {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getMarkRadius() {
|
||||||
|
return MARK_RADIUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setMarkRadius(int markRadius) {
|
||||||
|
MARK_RADIUS = markRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -17,13 +17,13 @@ public class StreamPacket {
|
|||||||
this.messageLength = messageLength;
|
this.messageLength = messageLength;
|
||||||
this.timeStamp = timeStamp;
|
this.timeStamp = timeStamp;
|
||||||
this.payload = payload;
|
this.payload = payload;
|
||||||
// System.out.println("type = " + this.type.toString());
|
System.out.println("type = " + this.type.toString());
|
||||||
//switch the packet type to deal with what ever specific packet you want to deal with
|
//switch the packet type to deal with what ever specific packet you want to deal with
|
||||||
// if (this.type == PacketType.XML_MESSAGE){
|
if (this.type == PacketType.XML_MESSAGE){
|
||||||
// System.out.println("--------");
|
System.out.println("--------");
|
||||||
// System.out.println(new String(payload));
|
System.out.println(new String(payload));
|
||||||
// StreamParser.parsePacket(this);
|
StreamParser.parsePacket(this);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketType getType() {
|
PacketType getType() {
|
||||||
|
|||||||
Reference in New Issue
Block a user