mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Mark drawing moved to MarkGroup class. RaceObject and it's sub classes now describe
all functionality required for a on screen object. Improved wakes. Branch currently untested. #story[812, 820] #refactor #implement.
This commit is contained in:
@@ -1,27 +1,35 @@
|
||||
package seng302.models.mark;
|
||||
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Circle;
|
||||
import javafx.scene.shape.Line;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import seng302.models.RaceObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
private static int MARK_RADIUS = 5;
|
||||
private static int LINE_THICKNESS = 2;
|
||||
private static double DASHED_GAP_LEN = 2d;
|
||||
private static double DASHED_LINE_LEN = 5d;
|
||||
|
||||
private List<Mark> marks = new ArrayList<>();
|
||||
private Mark mainMark;
|
||||
private double[] nodePixelVelocitiesX;
|
||||
private double[] nodePixelVelocitiesY;
|
||||
private Point2D[] nodeDestinations;
|
||||
|
||||
public MarkGroup (Mark mark, Point2D... points) {
|
||||
marks.add(mark);
|
||||
mainMark = mark;
|
||||
Color color = Color.BLACK;
|
||||
if (mark.getName().equals("Start")){
|
||||
color = Color.GREEN;
|
||||
@@ -31,11 +39,20 @@ public class MarkGroup extends RaceObject {
|
||||
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));
|
||||
marks.add(((GateMark) mark).getSingleMark1());
|
||||
marks.add(((GateMark) mark).getSingleMark2());
|
||||
super.getChildren().add(
|
||||
new Circle(
|
||||
points[1].getX() - points[0].getX(),
|
||||
points[1].getY() - points[0].getY(),
|
||||
(points[1].getX() - points[0].getX() / 2),
|
||||
(points[1].getY() - points[0].getY() / 2),
|
||||
MARK_RADIUS,
|
||||
color
|
||||
)
|
||||
);
|
||||
super.getChildren().add(
|
||||
new Circle(
|
||||
-(points[1].getX() - points[0].getX() / 2),
|
||||
-(points[1].getY() - points[0].getY() / 2),
|
||||
MARK_RADIUS,
|
||||
color
|
||||
)
|
||||
@@ -46,33 +63,60 @@ public class MarkGroup extends RaceObject {
|
||||
points[1].getX() - points[0].getX(),
|
||||
points[1].getY() - points[0].getY()
|
||||
);
|
||||
line.setStrokeWidth(2);
|
||||
line.setStrokeWidth(LINE_THICKNESS);
|
||||
if (mark.getMarkType() == MarkType.OPEN_GATE) {
|
||||
line.getStrokeDashArray().addAll(3d, 5d);
|
||||
line.getStrokeDashArray().addAll(DASHED_GAP_LEN, DASHED_LINE_LEN);
|
||||
}
|
||||
super.getChildren().add(line);
|
||||
nodePixelVelocitiesX = new double[2];
|
||||
nodePixelVelocitiesY = new double[2];
|
||||
nodeDestinations = new Point2D[2];
|
||||
}
|
||||
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, 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;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDestination (double x, double y) {
|
||||
|
||||
public void setDestination (double x, double y, int... raceIds) {
|
||||
int childrenIndex = -1;
|
||||
for (Mark mark : marks) {
|
||||
for (int id : raceIds)
|
||||
if (id == mark.getId() && childrenIndex != -1)
|
||||
setDestinationChild(x, y, childrenIndex);
|
||||
else if (id == mark.getId())
|
||||
setDestinationGroup(x, y);
|
||||
childrenIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
public void setMarkDestination (int markId, double x, double y) {
|
||||
|
||||
}
|
||||
public void updatePosition (double timeInterval) {
|
||||
|
||||
private void setDestinationChild (double x, double y, int childIndex) {
|
||||
double relativeX = x - super.getLayoutX();
|
||||
double relativeY = y - super.getLayoutY();
|
||||
this.nodeDestinations[childIndex] = new Point2D(relativeX, relativeY);
|
||||
this.nodePixelVelocitiesX[childIndex] = (relativeX - super.getChildren().get(childIndex).getLayoutX()) / expectedUpdateInterval;
|
||||
this.nodePixelVelocitiesY[childIndex] = (relativeY - super.getChildren().get(childIndex).getLayoutY()) / expectedUpdateInterval;
|
||||
}
|
||||
|
||||
public void moveTo (double x, double y, double rotation) {
|
||||
moveTo(x, y);
|
||||
private void setDestinationGroup (double x, double y) {
|
||||
pixelVelocityX = (x - super.getLayoutX()) / expectedUpdateInterval;
|
||||
pixelVelocityY = (y - super.getLayoutY()) / expectedUpdateInterval;
|
||||
}
|
||||
|
||||
|
||||
public void rotateTo (double rotation) {
|
||||
super.getTransforms().clear();
|
||||
super.getTransforms().add(
|
||||
new Rotate(
|
||||
@@ -83,20 +127,74 @@ public class MarkGroup extends RaceObject {
|
||||
);
|
||||
}
|
||||
|
||||
public void updatePosition (double timeInterval) {
|
||||
double x = pixelVelocityX * timeInterval;
|
||||
double y = pixelVelocityY * timeInterval;
|
||||
double rotation = rotationalVelocity * timeInterval;
|
||||
moveGroupBy(x, y, rotation);
|
||||
updateChildren(timeInterval);
|
||||
}
|
||||
|
||||
public void moveGroupBy (double x, double y, double rotation) {
|
||||
super.setLayoutX(super.getLayoutX() + x);
|
||||
super.setLayoutY(super.getOpacity() + y);
|
||||
rotateTo(rotation + currentRotation);
|
||||
}
|
||||
|
||||
private void updateChildren (double timeInterval) {
|
||||
if (mainMark.getMarkType() != MarkType.SINGLE_MARK) {
|
||||
Circle mark = (Circle) super.getChildren().get(0);
|
||||
if (nodePixelVelocitiesX[0] > 0 && mark.getLayoutX() >= nodeDestinations[0].getX()) {
|
||||
nodePixelVelocitiesX[0] = 0;
|
||||
} else if (nodePixelVelocitiesX[0] < 0 && mark.getLayoutX() <= nodeDestinations[0].getX()) {
|
||||
nodePixelVelocitiesX[0] = 0;
|
||||
} else {
|
||||
mark.setLayoutX(mark.getLayoutX() + nodePixelVelocitiesX[0] * timeInterval);
|
||||
mark.setLayoutY(mark.getLayoutY() + nodePixelVelocitiesY[0] * timeInterval);
|
||||
}
|
||||
if (nodePixelVelocitiesY[0] >= 0 && mark.getLayoutY() > nodeDestinations[0].getY()) {
|
||||
nodePixelVelocitiesY[0] = 0;
|
||||
} else if (nodePixelVelocitiesY[0] < 0 && mark.getLayoutY() <= nodeDestinations[0].getY()) {
|
||||
nodePixelVelocitiesY[0] = 0;
|
||||
} else {
|
||||
mark.setLayoutX(mark.getLayoutX() + nodePixelVelocitiesX[0] * timeInterval);
|
||||
mark.setLayoutY(mark.getLayoutY() + nodePixelVelocitiesY[0] * timeInterval);
|
||||
}
|
||||
mark = (Circle) super.getChildren().get(1);
|
||||
if (nodePixelVelocitiesX[1] > 0 && mark.getLayoutX() >= nodeDestinations[1].getX()) {
|
||||
nodePixelVelocitiesX[1] = 0;
|
||||
} else if (nodePixelVelocitiesX[1] < 0 && mark.getLayoutX() <= nodeDestinations[1].getX()) {
|
||||
nodePixelVelocitiesX[1] = 0;
|
||||
} else {
|
||||
mark.setLayoutX(mark.getLayoutX() + nodePixelVelocitiesX[1] * timeInterval);
|
||||
mark.setLayoutY(mark.getLayoutY() + nodePixelVelocitiesY[1] * timeInterval);
|
||||
}
|
||||
if (nodePixelVelocitiesY[1] >= 0 && mark.getLayoutY() > nodeDestinations[1].getY()) {
|
||||
nodePixelVelocitiesY[1] = 0;
|
||||
} else if (nodePixelVelocitiesY[1] < 0 && mark.getLayoutY() <= nodeDestinations[1].getY()) {
|
||||
nodePixelVelocitiesY[1] = 0;
|
||||
} else {
|
||||
mark.setLayoutX(mark.getLayoutX() + nodePixelVelocitiesX[1] * timeInterval);
|
||||
mark.setLayoutY(mark.getLayoutY() + nodePixelVelocitiesY[1] * timeInterval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void moveTo (double x, double y, double rotation) {
|
||||
moveTo(x, y);
|
||||
rotateTo(rotation);
|
||||
}
|
||||
|
||||
public void moveTo (double x, double y) {
|
||||
super.setLayoutX(x);
|
||||
super.setLayoutY(y);
|
||||
}
|
||||
|
||||
public boolean hasRaceId (int... raceIds) {
|
||||
for (int id : raceIds) {
|
||||
for (int id : raceIds)
|
||||
for (Mark mark : marks)
|
||||
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 () {
|
||||
@@ -111,4 +209,12 @@ public class MarkGroup extends RaceObject {
|
||||
MARK_RADIUS = markRadius;
|
||||
}
|
||||
|
||||
public int[] getRaceIds () {
|
||||
int[] idArray = new int[marks.size()];
|
||||
int i = 0;
|
||||
for (Mark mark : marks)
|
||||
idArray[i++] = mark.getId();
|
||||
return idArray;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user