mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Starting new wake implementation.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package seng302.models;
|
package seng302.models;
|
||||||
|
|
||||||
import javafx.geometry.Point2D;
|
import javafx.geometry.Point2D;
|
||||||
|
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.Line;
|
import javafx.scene.shape.Line;
|
||||||
@@ -24,20 +25,23 @@ public class BoatGroup extends RaceObject{
|
|||||||
private static final double VELOCITY_WAKE_RATIO = 2d;
|
private static final double VELOCITY_WAKE_RATIO = 2d;
|
||||||
private static final double BOAT_HEIGHT = 15d;
|
private static final double BOAT_HEIGHT = 15d;
|
||||||
private static final double BOAT_WIDTH = 10d;
|
private static final double BOAT_WIDTH = 10d;
|
||||||
|
private static final int LINE_INTERVAL = 120;
|
||||||
//Time between sections of race - Should be changed to 200 for actual program.
|
//Time between sections of race - Should be changed to 200 for actual program.
|
||||||
private static double expectedUpdateInterval = 200;
|
private static double expectedUpdateInterval = 200;
|
||||||
private static int WAKE_FRAME_INTERVAL = 30;
|
private static int WAKE_FRAME_INTERVAL = 30;
|
||||||
private double framesForNewLine = 0;
|
private double framesForNewLine = LINE_INTERVAL;
|
||||||
private Point2D lastPoint;
|
private Point2D lastPoint;
|
||||||
|
|
||||||
private Boat boat;
|
private Boat boat;
|
||||||
private int wakeCounter = WAKE_FRAME_INTERVAL;
|
private int wakeCounter = WAKE_FRAME_INTERVAL;
|
||||||
private List<Wake> wakes = new ArrayList<>();
|
private List<Wake> wakes = new ArrayList<>();
|
||||||
private List<Line> lines = new ArrayList<>();
|
//private List<Line> lines = new ArrayList<>();
|
||||||
|
private Group lines = new Group();
|
||||||
private Polygon boatPoly;
|
private Polygon boatPoly;
|
||||||
// private Polygon wakePoly;
|
// private Polygon wakePoly;
|
||||||
private Text teamNameObject;
|
private Text teamNameObject;
|
||||||
private Text velocityObject;
|
private Text velocityObject;
|
||||||
|
private Wake2 wake;
|
||||||
|
|
||||||
public BoatGroup (Boat boat, Color color){
|
public BoatGroup (Boat boat, Color color){
|
||||||
this.boat = boat;
|
this.boat = boat;
|
||||||
@@ -74,8 +78,9 @@ public class BoatGroup extends RaceObject{
|
|||||||
velocityObject.setY(VELOCITY_Y_OFFSET);
|
velocityObject.setY(VELOCITY_Y_OFFSET);
|
||||||
velocityObject.relocate(velocityObject.getX(), velocityObject.getY());
|
velocityObject.relocate(velocityObject.getX(), velocityObject.getY());
|
||||||
|
|
||||||
|
wake = new Wake2(0, 0, 0);
|
||||||
// super.getChildren().addAll(wakePoly, boatPoly, teamNameObject, velocityObject);
|
// super.getChildren().addAll(wakePoly, boatPoly, teamNameObject, velocityObject);
|
||||||
super.getChildren().addAll(teamNameObject, velocityObject, boatPoly);
|
super.getChildren().addAll(lines, wake, teamNameObject, velocityObject, boatPoly);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initChildren (Color color) {
|
private void initChildren (Color color) {
|
||||||
@@ -119,11 +124,12 @@ public class BoatGroup extends RaceObject{
|
|||||||
teamNameObject.setLayoutY(y);
|
teamNameObject.setLayoutY(y);
|
||||||
velocityObject.setLayoutX(x);
|
velocityObject.setLayoutX(x);
|
||||||
velocityObject.setLayoutY(y);
|
velocityObject.setLayoutY(y);
|
||||||
|
wake.moveTo(x, y, currentRotation);
|
||||||
// wakePoly.setLayoutX(x);
|
// wakePoly.setLayoutX(x);
|
||||||
// wakePoly.setLayoutY(y);
|
// wakePoly.setLayoutY(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePosition (double timeInterval) {
|
public void updatePosition (long timeInterval) {
|
||||||
double dx = pixelVelocityX * timeInterval;
|
double dx = pixelVelocityX * timeInterval;
|
||||||
double dy = pixelVelocityY * timeInterval;
|
double dy = pixelVelocityY * timeInterval;
|
||||||
double rotation = 0d;
|
double rotation = 0d;
|
||||||
@@ -139,44 +145,51 @@ public class BoatGroup extends RaceObject{
|
|||||||
// super.getChildren().remove(wake);
|
// super.getChildren().remove(wake);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
for (Wake wake : wakes) {
|
// for (Wake wake : wakes) {
|
||||||
if (wake.updatePosition(timeInterval)) {
|
// if (wake.updatePosition(timeInterval)) {
|
||||||
super.getChildren().remove(wake);
|
// super.getChildren().remove(wake);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (wakeCounter-- == 0) {
|
// if (wakeCounter-- == 0) {
|
||||||
// if (boat.getShortName().equals("BAR"))
|
//// if (boat.getShortName().equals("BAR"))
|
||||||
// System.out.println("thinking");
|
//// System.out.println("thinking");
|
||||||
wakeCounter = WAKE_FRAME_INTERVAL;
|
// wakeCounter = WAKE_FRAME_INTERVAL;
|
||||||
if (pixelVelocityX > 0 && pixelVelocityY > 0) {
|
// if (pixelVelocityX > 0 && pixelVelocityY > 0) {
|
||||||
// super.getChildren().add(
|
//// super.getChildren().add(
|
||||||
// new Wake(
|
//// new Wake(
|
||||||
// super.getLayoutX() + BOAT_HEIGHT, super.getLayoutY() + BOAT_HEIGHT, pixelVelocityX, pixelVelocityY
|
//// super.getLayoutX() + BOAT_HEIGHT, super.getLayoutY() + BOAT_HEIGHT, pixelVelocityX, pixelVelocityY
|
||||||
// )
|
//// )
|
||||||
// );
|
//// );
|
||||||
Wake wake = new Wake(
|
// Wake wake = new Wake(
|
||||||
boatPoly.getLayoutX(),
|
// boatPoly.getLayoutX(),
|
||||||
boatPoly.getLayoutY(),
|
// boatPoly.getLayoutY(),
|
||||||
pixelVelocityX,
|
// pixelVelocityX,
|
||||||
pixelVelocityY, rotation);
|
// pixelVelocityY, rotation);
|
||||||
// wake.getTransforms().clear();
|
//// wake.getTransforms().clear();
|
||||||
// wake.getTransforms().add(new Rotate(rotation, 0, 0));
|
//// wake.getTransforms().add(new Rotate(rotation, 0, 0));
|
||||||
super.getChildren().add(wake);
|
// super.getChildren().add(wake);
|
||||||
wakes.add(wake);
|
// wakes.add(wake);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
if (framesForNewLine == 0) {
|
if (framesForNewLine == 0) {
|
||||||
framesForNewLine = 121;
|
framesForNewLine = LINE_INTERVAL;
|
||||||
if (lastPoint != null) {
|
if (lastPoint != null) {
|
||||||
Line l = new Line(lastPoint.getX(), lastPoint.getY(), boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
Line l = new Line(
|
||||||
l.getStrokeDashArray().setAll(4d, 4d);
|
lastPoint.getX(),
|
||||||
lines.add(l);
|
lastPoint.getY(),
|
||||||
super.getChildren().add(l);
|
boatPoly.getLayoutX(),
|
||||||
|
boatPoly.getLayoutY()
|
||||||
|
);
|
||||||
|
l.getStrokeDashArray().setAll(4d, 6d);
|
||||||
|
l.setStroke(boatPoly.getFill());
|
||||||
|
//lines.add(l);
|
||||||
|
lines.getChildren().add(l);
|
||||||
}
|
}
|
||||||
lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
||||||
}
|
}
|
||||||
framesForNewLine -= 1;
|
framesForNewLine -= 1;
|
||||||
|
wake.updatePosition(timeInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDestination (double newXValue, double newYValue, double rotation, int... raceIds) {
|
public void setDestination (double newXValue, double newYValue, double rotation, int... raceIds) {
|
||||||
@@ -187,6 +200,7 @@ public class BoatGroup extends RaceObject{
|
|||||||
this.rotationalGoal = rotation;
|
this.rotationalGoal = rotation;
|
||||||
calculateRotationalVelocity();
|
calculateRotationalVelocity();
|
||||||
rotateTo(rotation);
|
rotateTo(rotation);
|
||||||
|
wake.setRotationalVelocity(rotationalVelocity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,11 +227,12 @@ public class BoatGroup extends RaceObject{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void rotateTo (double rotation) {
|
public void rotateTo (double rotation) {
|
||||||
if(rotation != 0) {
|
//if(rotation != 0) {
|
||||||
rotationalGoal = rotation;
|
//rotationalGoal = rotation;
|
||||||
|
currentRotation = rotation;
|
||||||
boatPoly.getTransforms().clear();
|
boatPoly.getTransforms().clear();
|
||||||
boatPoly.getTransforms().add(new Rotate(rotation, BOAT_WIDTH / 2, 0));
|
boatPoly.getTransforms().add(new Rotate(rotation, BOAT_WIDTH / 2, 0));
|
||||||
}
|
//}
|
||||||
// wakePoly.getTransforms().clear();
|
// wakePoly.getTransforms().clear();
|
||||||
// wakePoly.getTransforms().add(new Rotate(rotation, 0, 0));
|
// wakePoly.getTransforms().add(new Rotate(rotation, 0, 0));
|
||||||
}
|
}
|
||||||
@@ -232,9 +247,7 @@ public class BoatGroup extends RaceObject{
|
|||||||
for (Wake wake : wakes) {
|
for (Wake wake : wakes) {
|
||||||
wake.setVisible(!wake.isVisible());
|
wake.setVisible(!wake.isVisible());
|
||||||
}
|
}
|
||||||
for (Line line : lines) {
|
lines.setVisible(!lines.isVisible());
|
||||||
line.setVisible(!line.isVisible());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boat getBoat() {
|
public Boat getBoat() {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public abstract class RaceObject extends Group {
|
|||||||
|
|
||||||
public abstract void setDestination (double x, double y, int... raceIds);
|
public abstract void setDestination (double x, double y, int... raceIds);
|
||||||
|
|
||||||
public abstract void updatePosition (double timeInterval);
|
public abstract void updatePosition (long timeInterval);
|
||||||
|
|
||||||
public abstract void moveTo (double x, double y, double rotation);
|
public abstract void moveTo (double x, double y, double rotation);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package seng302.models;
|
||||||
|
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.scene.shape.Arc;
|
||||||
|
import javafx.scene.transform.Rotate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by cir27 on 28/04/17.
|
||||||
|
*/
|
||||||
|
class Wake2 extends Arc {
|
||||||
|
private final double OPACITY_INCREASE = -0.2;
|
||||||
|
private final double RADIUS_INCREASE = 10;
|
||||||
|
private final int DELAY = 60;
|
||||||
|
private double opacity;
|
||||||
|
private double rotationalVelocity;
|
||||||
|
private Wake2 subWake;
|
||||||
|
private boolean hasSubWake = false;
|
||||||
|
private int delayCount = DELAY;
|
||||||
|
|
||||||
|
Wake2 (double startingX, double startingY, double rotationalVelocity) {
|
||||||
|
super(startingX, startingY, 30, 30, 150, 60);
|
||||||
|
opacity = 1.0;
|
||||||
|
super.setFill(new Color(0.0, 0.0, 0.0, opacity));
|
||||||
|
subWake = new Wake2(
|
||||||
|
startingX,
|
||||||
|
startingY,
|
||||||
|
super.getRadiusX() + RADIUS_INCREASE,
|
||||||
|
rotationalVelocity,
|
||||||
|
opacity + OPACITY_INCREASE
|
||||||
|
);
|
||||||
|
hasSubWake = true;
|
||||||
|
this.rotationalVelocity = rotationalVelocity;
|
||||||
|
|
||||||
|
}
|
||||||
|
Wake2 (double startingX, double startingY, double radius, double rotationalVelocity, double opacity) {
|
||||||
|
super(startingX, startingY, radius, radius, 150, 60);
|
||||||
|
super.setFill(new Color(0.0, 0.0, 0.0, opacity));
|
||||||
|
this.opacity = opacity;
|
||||||
|
if (!(opacity < 0)) {
|
||||||
|
subWake = new Wake2(
|
||||||
|
startingX,
|
||||||
|
startingY,
|
||||||
|
super.getRadiusX() + RADIUS_INCREASE,
|
||||||
|
rotationalVelocity,
|
||||||
|
opacity + OPACITY_INCREASE
|
||||||
|
);
|
||||||
|
hasSubWake = true;
|
||||||
|
}
|
||||||
|
this.rotationalVelocity = rotationalVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setRotationalVelocity (double rotationalVelocity) {
|
||||||
|
this.rotationalVelocity = rotationalVelocity;
|
||||||
|
delayCount = DELAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
void updatePosition (long timeInterval) {
|
||||||
|
if (delayCount-- == 0)
|
||||||
|
subWake.setRotationalVelocity(rotationalVelocity);
|
||||||
|
super.getTransforms().clear();
|
||||||
|
super.getTransforms().add(
|
||||||
|
new Rotate(
|
||||||
|
rotationalVelocity * timeInterval,
|
||||||
|
super.getCenterX(),
|
||||||
|
super.getCenterY()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if(hasSubWake)
|
||||||
|
subWake.updatePosition(timeInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
void moveTo (double x, double y, double rotation) {
|
||||||
|
super.setLayoutX(x);
|
||||||
|
super.setLayoutY(y);
|
||||||
|
super.getTransforms().clear();
|
||||||
|
super.getTransforms().add(
|
||||||
|
new Rotate(
|
||||||
|
rotation,
|
||||||
|
super.getCenterX(),
|
||||||
|
super.getCenterY()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if(hasSubWake)
|
||||||
|
subWake.moveTo(x, y, rotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -156,7 +156,7 @@ public class MarkGroup extends RaceObject {
|
|||||||
super.getTransforms().add(new Rotate(rotation, 0 , 0));
|
super.getTransforms().add(new Rotate(rotation, 0 , 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePosition (double timeInterval) {
|
public void updatePosition (long timeInterval) {
|
||||||
double x = pixelVelocityX * timeInterval;
|
double x = pixelVelocityX * timeInterval;
|
||||||
double y = pixelVelocityY * timeInterval;
|
double y = pixelVelocityY * timeInterval;
|
||||||
double rotation = rotationalVelocity * timeInterval;
|
double rotation = rotationalVelocity * timeInterval;
|
||||||
|
|||||||
Reference in New Issue
Block a user