mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Changed BoatPolygon is now a group instead of a polygon and is called BoatGroup.
BoatPolygon's functionality was more maintainable and scalable by having it extend Group. #story30c
This commit is contained in:
@@ -12,7 +12,7 @@ import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.util.Pair;
|
||||
import seng302.models.Boat;
|
||||
import seng302.models.BoatPolygon;
|
||||
import seng302.models.BoatGroup;
|
||||
import seng302.models.Colors;
|
||||
import seng302.models.mark.GateMark;
|
||||
import seng302.models.mark.Mark;
|
||||
@@ -35,7 +35,7 @@ public class CanvasController {
|
||||
private ResizableCanvas canvas;
|
||||
private Group group;
|
||||
private GraphicsContext gc;
|
||||
private List<BoatPolygon> boatPolygons = new ArrayList<>();
|
||||
private List<BoatGroup> boatGroups = new ArrayList<>();
|
||||
|
||||
private final int MARK_SIZE = 10;
|
||||
private final int BUFFER_SIZE = 25;
|
||||
@@ -142,35 +142,47 @@ public class CanvasController {
|
||||
public void handle(long now) {
|
||||
boolean raceFinished = true;
|
||||
boolean descending;
|
||||
boolean leftToRight;
|
||||
int boatIndex = 0;
|
||||
Mark nextMark;
|
||||
if (countdown == 0) {
|
||||
for (BoatPolygon bp : boatPolygons) {
|
||||
for (BoatGroup boatGroup : boatGroups) {
|
||||
if (currentRaceMarker[boatIndex] < marks.size()) {
|
||||
if (currentRaceMarker[boatIndex] == 6) {
|
||||
int debugLine = 4;
|
||||
}
|
||||
double xb4 = bp.getLayoutX();
|
||||
double yb4 = bp.getLayoutY();
|
||||
double xb4 = boatGroup.getLayoutX();
|
||||
double yb4 = boatGroup.getLayoutY();
|
||||
nextMark = marks.get(currentRaceMarker[boatIndex]);
|
||||
if (nextMark.getY() > bp.getLayoutY())
|
||||
descending = true;
|
||||
else
|
||||
descending = false;
|
||||
bp.updatePosition(1000 / 60);
|
||||
if (descending && nextMark.getY() < bp.getLayoutY()) {
|
||||
|
||||
descending = nextMark.getY() > boatGroup.getLayoutY();
|
||||
leftToRight = nextMark.getX() < boatGroup.getLayoutX();
|
||||
|
||||
boatGroup.updatePosition(1000 / 60);
|
||||
if (descending && nextMark.getY() < boatGroup.getLayoutY()) {
|
||||
currentRaceMarker[boatIndex]++;
|
||||
bp.setDestination(
|
||||
boatGroup.setDestination(
|
||||
marks.get(currentRaceMarker[boatIndex]).getX(), marks.get(currentRaceMarker[boatIndex]).getY()
|
||||
);
|
||||
} else if (!descending && nextMark.getY() > bp.getLayoutY()) {
|
||||
} else if (!descending && nextMark.getY() > boatGroup.getLayoutY()) {
|
||||
currentRaceMarker[boatIndex]++;
|
||||
bp.setDestination(
|
||||
boatGroup.setDestination(
|
||||
marks.get(currentRaceMarker[boatIndex]).getX(), marks.get(currentRaceMarker[boatIndex]).getY()
|
||||
);
|
||||
} else if (leftToRight && nextMark.getX() > boatGroup.getLayoutX()) {
|
||||
currentRaceMarker[boatIndex]++;
|
||||
boatGroup.setDestination(
|
||||
marks.get(currentRaceMarker[boatIndex]).getX(), marks.get(currentRaceMarker[boatIndex]).getY()
|
||||
);
|
||||
} else if (!leftToRight && nextMark.getX() < boatGroup.getLayoutX()) {
|
||||
currentRaceMarker[boatIndex]++;
|
||||
boatGroup.setDestination(
|
||||
marks.get(currentRaceMarker[boatIndex]).getX(), marks.get(currentRaceMarker[boatIndex]).getY()
|
||||
);
|
||||
}
|
||||
double xnew = bp.getLayoutX();
|
||||
double ynew = bp.getLayoutY();
|
||||
|
||||
double xnew = boatGroup.getLayoutX();
|
||||
double ynew = boatGroup.getLayoutY();
|
||||
double dx = xnew - xb4;
|
||||
double dy = ynew -yb4;
|
||||
raceFinished = false;
|
||||
@@ -245,15 +257,12 @@ public class CanvasController {
|
||||
Double firstMarkY = (double) marks.get(1).getY();
|
||||
|
||||
for (Boat boat : boats) {
|
||||
BoatPolygon bp = new BoatPolygon(boat, Colors.getColor());
|
||||
bp.moveBoatTo(startingX, startingY, 0d);
|
||||
bp.setDestination(firstMarkX, firstMarkY);
|
||||
bp.forceRotation();
|
||||
group.getChildren().add(bp.getWake());
|
||||
group.getChildren().add(bp);
|
||||
group.getChildren().add(bp.getTeamNameObject());
|
||||
group.getChildren().add(bp.getVelocityObject());
|
||||
boatPolygons.add(bp);
|
||||
BoatGroup boatGroup = new BoatGroup(boat, Colors.getColor());
|
||||
boatGroup.moveBoatTo(startingX, startingY, 0d);
|
||||
boatGroup.setDestination(firstMarkX, firstMarkY);
|
||||
boatGroup.forceRotation();
|
||||
group.getChildren().add(boatGroup);
|
||||
boatGroups.add(boatGroup);
|
||||
// drawBoat(boat.getLongitude(), boat.getLatitude(), boat.getColor(), boat.getShortName(), boat.getSpeedInKnots(), boat.getHeading());
|
||||
}
|
||||
}
|
||||
|
||||
+56
-74
@@ -1,7 +1,7 @@
|
||||
package seng302.models;
|
||||
|
||||
|
||||
import com.sun.xml.internal.bind.v2.TODO;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.text.Text;
|
||||
@@ -9,10 +9,9 @@ import javafx.scene.transform.Rotate;
|
||||
import javafx.scene.transform.Translate;
|
||||
|
||||
/**
|
||||
* Created by cir27 on 24/04/17.
|
||||
* Created by CJIRWIN on 25/04/2017.
|
||||
*/
|
||||
public class BoatPolygon extends Polygon {
|
||||
|
||||
public class BoatGroup extends Group{
|
||||
private static final double TEAMNAME_X_OFFSET = 15d;
|
||||
private static final double TEAMNAME_Y_OFFSET = -20d;
|
||||
private static final double VELOCITY_X_OFFSET = 15d;
|
||||
@@ -21,52 +20,66 @@ public class BoatPolygon extends Polygon {
|
||||
private static final double BOAT_HEIGHT = 15d;
|
||||
private static final double BOAT_WIDTH = 10d;
|
||||
//Time between sections of race - Should be changed to 200 for actual program.
|
||||
private static double expectedUpdateInterval = 5000;
|
||||
private static double expectedUpdateInterval = 2000;
|
||||
|
||||
private Boat boat;
|
||||
private Polygon wake;
|
||||
private Text teamNameObject;
|
||||
private Text velocityObject;
|
||||
|
||||
private double rotationalGoal;
|
||||
private double currentRotation;
|
||||
private double rotationalVelocity;
|
||||
private double pixelVelocityX;
|
||||
private double pixelVelocityY;
|
||||
//private double destinationX;
|
||||
//private double destinationY;
|
||||
|
||||
public BoatPolygon (Boat boat, Color color){
|
||||
public BoatGroup (Boat boat, Color color){
|
||||
super();
|
||||
super.setFill(color);
|
||||
super.getPoints().addAll(
|
||||
BOAT_WIDTH / 2, 0.0,
|
||||
BOAT_WIDTH , BOAT_HEIGHT,
|
||||
0.0 , BOAT_HEIGHT
|
||||
);
|
||||
this.boat = boat;
|
||||
initAnnotations();
|
||||
initChildren(color);
|
||||
}
|
||||
|
||||
public BoatPolygon (Boat boat, Color color, double... points)
|
||||
public BoatGroup (Boat boat, Color color, double... points)
|
||||
{
|
||||
super(points);
|
||||
super.setFill(color);
|
||||
this.boat = boat;
|
||||
initAnnotations();
|
||||
super();
|
||||
initChildren(color, points);
|
||||
}
|
||||
|
||||
private void initAnnotations ()
|
||||
{
|
||||
wake = new Polygon();
|
||||
wake.setFill(Color.DARKBLUE);
|
||||
wake.getPoints().addAll(
|
||||
private void initChildren (Color color, double... points) {
|
||||
Polygon boatPoly = new Polygon(points);
|
||||
boatPoly.setFill(color);
|
||||
|
||||
Polygon wake = new Polygon(
|
||||
5.0,0.0,
|
||||
10.0, boat.getVelocity() * VELOCITY_WAKE_RATIO,
|
||||
0.0, boat.getVelocity() * VELOCITY_WAKE_RATIO
|
||||
);
|
||||
teamNameObject = new Text(boat.getShortName());
|
||||
velocityObject = new Text(String.valueOf(boat.getVelocity()));
|
||||
wake.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.setX(TEAMNAME_X_OFFSET);
|
||||
teamNameObject.setY(TEAMNAME_Y_OFFSET);
|
||||
teamNameObject.relocate(teamNameObject.getX(), teamNameObject.getY());
|
||||
|
||||
velocityObject.setX(VELOCITY_X_OFFSET);
|
||||
velocityObject.setY(VELOCITY_Y_OFFSET);
|
||||
velocityObject.relocate(velocityObject.getX(), velocityObject.getY());
|
||||
|
||||
wake.setLayoutX(0);
|
||||
wake.setLayoutY(0);
|
||||
wake.relocate(wake.getLayoutX(), wake.getLayoutY());
|
||||
|
||||
super.getChildren().addAll(boatPoly, wake, teamNameObject, velocityObject);
|
||||
}
|
||||
|
||||
private void initChildren (Color color) {
|
||||
initChildren(color,
|
||||
BOAT_WIDTH / 2, 0.0,
|
||||
BOAT_WIDTH, BOAT_HEIGHT,
|
||||
0.0, BOAT_HEIGHT);
|
||||
}
|
||||
/**
|
||||
* Moves the boat and its children annotations from its current coordinates by specified amounts.
|
||||
@@ -76,19 +89,6 @@ public class BoatPolygon extends Polygon {
|
||||
void moveBy(Double dx, Double dy, Double rotation) {
|
||||
super.setLayoutX(super.getLayoutX() + dx);
|
||||
super.setLayoutY(super.getLayoutY() + dy);
|
||||
super.relocate(super.getLayoutX(), super.getLayoutY());
|
||||
|
||||
teamNameObject.setX(teamNameObject.getX() + dx);
|
||||
teamNameObject.setY(teamNameObject.getY() + dy);
|
||||
teamNameObject.relocate(teamNameObject.getX(), teamNameObject.getY());
|
||||
|
||||
velocityObject.setX(velocityObject.getX() + dx);
|
||||
velocityObject.setY(velocityObject.getY() + dy);
|
||||
velocityObject.relocate(velocityObject.getX(), velocityObject.getY());
|
||||
|
||||
wake.setLayoutX(wake.getLayoutX() + dx);
|
||||
wake.setLayoutY(wake.getLayoutY() + dy);
|
||||
wake.relocate(wake.getLayoutX(), wake.getLayoutY());
|
||||
rotateBoat(rotation);
|
||||
}
|
||||
|
||||
@@ -98,21 +98,7 @@ public class BoatPolygon extends Polygon {
|
||||
* @param y The Y coordinate to move the boat to
|
||||
*/
|
||||
public void moveBoatTo(Double x, Double y, Double rotation) {
|
||||
super.setLayoutX(x);
|
||||
super.setLayoutY(y);
|
||||
super.relocate(super.getLayoutX(), super.getLayoutY());
|
||||
|
||||
teamNameObject.setX(x + TEAMNAME_X_OFFSET);
|
||||
teamNameObject.setY(y + TEAMNAME_Y_OFFSET);
|
||||
teamNameObject.relocate(teamNameObject.getX(), teamNameObject.getY());
|
||||
|
||||
velocityObject.setX(x + VELOCITY_X_OFFSET);
|
||||
velocityObject.setY(y + VELOCITY_Y_OFFSET);
|
||||
velocityObject.relocate(velocityObject.getX(), velocityObject.getY());
|
||||
|
||||
wake.setLayoutX(x);
|
||||
wake.setLayoutY(y);
|
||||
wake.relocate(wake.getLayoutX(), wake.getLayoutY());
|
||||
super.relocate(x, y);
|
||||
currentRotation = 0;
|
||||
rotateBoat(rotation);
|
||||
}
|
||||
@@ -160,8 +146,10 @@ public class BoatPolygon extends Polygon {
|
||||
|
||||
public void rotateBoat (double rotationDeg) {
|
||||
currentRotation += rotationDeg;
|
||||
super.getTransforms().clear();
|
||||
super.getTransforms().add(new Rotate(currentRotation, BOAT_WIDTH/2, 0));
|
||||
Node boatPoly = super.getChildren().get(0);
|
||||
boatPoly.getTransforms().clear();
|
||||
boatPoly.getTransforms().add(new Rotate(currentRotation, 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(currentRotation, BOAT_WIDTH/2, -BOAT_HEIGHT));
|
||||
@@ -172,22 +160,16 @@ public class BoatPolygon extends Polygon {
|
||||
}
|
||||
|
||||
public static void setExpectedUpdateInterval(double expectedUpdateInterval) {
|
||||
BoatPolygon.expectedUpdateInterval = expectedUpdateInterval;
|
||||
}
|
||||
|
||||
public Polygon getWake() {
|
||||
return wake;
|
||||
}
|
||||
|
||||
public Text getTeamNameObject() {
|
||||
return teamNameObject;
|
||||
}
|
||||
|
||||
public Text getVelocityObject() {
|
||||
return velocityObject;
|
||||
BoatGroup.expectedUpdateInterval = expectedUpdateInterval;
|
||||
}
|
||||
|
||||
public void forceRotation () {
|
||||
rotateBoat (rotationalGoal - currentRotation);
|
||||
}
|
||||
|
||||
public void toogleAnnotations () {
|
||||
super.getChildren().get(1).setVisible(false);
|
||||
super.getChildren().get(2).setVisible(false);
|
||||
super.getChildren().get(3).setVisible(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user