mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +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) {
|
||||
Point2D p2d = latLonToXY(p.getX(), p.getY());
|
||||
//System.out.println("p2d = " + p2d);
|
||||
if (!boatGroup.getBoat().isSamePos(p2d)) {
|
||||
if (!boatGroup.isSamePos(p2d)) {
|
||||
//System.out.println("p.toString() = " + p.toString());
|
||||
double heading = 360.0 / 0xffff * p.getZ();
|
||||
//System.out.println("heading = " + heading);
|
||||
@@ -288,7 +288,7 @@ public class CanvasController {
|
||||
|
||||
for (Boat boat : boats) {
|
||||
BoatGroup boatGroup = new BoatGroup(boat, Colors.getColor());
|
||||
boatGroup.moveBoatTo(startingX, startingY, 0d);
|
||||
boatGroup.moveTo(startingX, startingY, 0d);
|
||||
boatGroup.setDestination(firstMarkX, firstMarkY);
|
||||
boatGroup.forceRotation();
|
||||
group.getChildren().add(boatGroup);
|
||||
|
||||
@@ -21,7 +21,6 @@ public class Boat {
|
||||
private int markLastPast;
|
||||
private String shortName;
|
||||
private int id;
|
||||
private Point2D currentPos;
|
||||
|
||||
public Boat(String teamName) {
|
||||
this.teamName = teamName;
|
||||
@@ -29,17 +28,8 @@ public class Boat {
|
||||
this.lat = 0.0;
|
||||
this.lon = 0.0;
|
||||
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.
|
||||
@@ -53,8 +43,6 @@ public class Boat {
|
||||
this.velocity = boatVelocity;
|
||||
this.shortName = shortName;
|
||||
this.id = id;
|
||||
currentPos = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package seng302.models;
|
||||
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Polygon;
|
||||
@@ -11,7 +10,7 @@ import javafx.scene.transform.Translate;
|
||||
/**
|
||||
* 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_Y_OFFSET = -20d;
|
||||
@@ -25,21 +24,13 @@ public class BoatGroup extends Group{
|
||||
|
||||
private Boat boat;
|
||||
|
||||
private double rotationalGoal;
|
||||
private double currentRotation;
|
||||
private double rotationalVelocity;
|
||||
private double pixelVelocityX;
|
||||
private double pixelVelocityY;
|
||||
|
||||
public BoatGroup (Boat boat, Color color){
|
||||
super();
|
||||
this.boat = boat;
|
||||
initChildren(color);
|
||||
}
|
||||
|
||||
public BoatGroup (Boat boat, Color color, double... points)
|
||||
{
|
||||
super();
|
||||
initChildren(color, points);
|
||||
}
|
||||
|
||||
@@ -87,7 +78,7 @@ public class BoatGroup extends Group{
|
||||
* @param dx The amount to move the X 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.setLayoutY(super.getLayoutY() + dy);
|
||||
rotateBoat(rotation);
|
||||
@@ -98,11 +89,15 @@ public class BoatGroup extends Group{
|
||||
* @param x The X 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.setLayoutY(y);
|
||||
currentRotation = 0;
|
||||
rotateBoat(rotation);
|
||||
}
|
||||
|
||||
public void updatePosition (double timeInterval) {
|
||||
@@ -202,7 +197,7 @@ public class BoatGroup extends Group{
|
||||
rotateBoat (rotationalGoal - currentRotation);
|
||||
}
|
||||
|
||||
public void toogleAnnotations () {
|
||||
public void toggleAnnotations () {
|
||||
super.getChildren().get(1).setVisible(false);
|
||||
super.getChildren().get(2).setVisible(false);
|
||||
super.getChildren().get(3).setVisible(false);
|
||||
@@ -211,4 +206,12 @@ public class BoatGroup extends Group{
|
||||
public Boat getBoat() {
|
||||
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 double latitude;
|
||||
private double longitude;
|
||||
private int id;
|
||||
Integer xValue;
|
||||
Integer yValue;
|
||||
|
||||
@@ -21,6 +22,7 @@ public abstract class Mark {
|
||||
public Mark (String name, MarkType markType) {
|
||||
this.name = name;
|
||||
this.markType = markType;
|
||||
id = 0;
|
||||
}
|
||||
|
||||
public Mark(String name, MarkType markType, double latitude, double longitude) {
|
||||
@@ -28,6 +30,7 @@ public abstract class Mark {
|
||||
this.markType = markType;
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
id = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,4 +143,12 @@ public abstract class Mark {
|
||||
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.timeStamp = timeStamp;
|
||||
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
|
||||
// if (this.type == PacketType.XML_MESSAGE){
|
||||
// System.out.println("--------");
|
||||
// System.out.println(new String(payload));
|
||||
// StreamParser.parsePacket(this);
|
||||
// }
|
||||
if (this.type == PacketType.XML_MESSAGE){
|
||||
System.out.println("--------");
|
||||
System.out.println(new String(payload));
|
||||
StreamParser.parsePacket(this);
|
||||
}
|
||||
}
|
||||
|
||||
PacketType getType() {
|
||||
|
||||
Reference in New Issue
Block a user