mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Further work on new wake system. Wakes turn correctly but need to scale with velocity and
eventually desync with the boats. Needs to reset to the boats position on straights.
This commit is contained in:
@@ -1,51 +1,94 @@
|
||||
package seng302.models;
|
||||
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Arc;
|
||||
import javafx.scene.shape.ArcType;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import javafx.scene.transform.Translate;
|
||||
|
||||
/**
|
||||
* Created by CJIRWIN on 27/04/2017.
|
||||
* By default wake is a group containing 5 arcs. Each arc starts from the same point. Each arc is larger and more
|
||||
* transparent than the last. On calling updatePositions() arcs rotate at velocities given by setRotationalVelocity().
|
||||
* The larger and more transparent an arc is the longer the delay before it rotates at the latest velocity. It is
|
||||
* assumed that rotationalVelocities() are set regularly as wakes do not stop rotating and an array of velocities needs
|
||||
* to be populated for the class to work as expected.
|
||||
*/
|
||||
class Wake extends Arc {
|
||||
class Wake extends Group {
|
||||
private final double OPACITY_INCREASE = -0.10;
|
||||
private final double RADIUS_INCREASE = 10;
|
||||
final int numWakes = 5;
|
||||
private double[] velocities = new double[numWakes * 3];
|
||||
private Arc[] arcs = new Arc[numWakes];
|
||||
private double[] rotations = new double[numWakes];
|
||||
private int velocitiesIndex = 0;
|
||||
|
||||
private static int VELOCITY_SCALE_FACTOR = 3;
|
||||
private static int MAX_LIFESPAN = 210;
|
||||
private static double LIFESPAN_PER_FRAME = 1.0 / MAX_LIFESPAN;
|
||||
//private static double LENGTH_PER_FRAME = 120 / MAX_LIFESPAN;
|
||||
private static double LENGTH_PER_FRAME = 0.25;
|
||||
|
||||
private double velocityX;
|
||||
private double velocityY;
|
||||
private double opacity;
|
||||
private int lifespan = MAX_LIFESPAN;
|
||||
|
||||
Wake (double startingX, double startingY, double velocityX, double velocityY, double rotation) {
|
||||
super(startingX, startingY, 20, 30, 180, 0);
|
||||
//super.setFill(Color.BLUE);
|
||||
super.setStroke(Color.DEEPSKYBLUE);
|
||||
super.setType(ArcType.OPEN);
|
||||
super.setFill(new Color(0, 0, 0 ,0));
|
||||
super.setStrokeWidth(2.0);
|
||||
super.getTransforms().add(new Rotate(rotation, 5, -15));
|
||||
// this.velocityX = -velocityX;
|
||||
// this.velocityY = -velocityY;
|
||||
this.velocityX = 0;
|
||||
this.velocityY = 0;
|
||||
/**
|
||||
* Create a wake at the given location.
|
||||
* @param startingX x location where the tip of wake arcs will be.
|
||||
* @param startingY y location where the tip of wake arcs will be.
|
||||
*/
|
||||
Wake(double startingX, double startingY) {
|
||||
super.setLayoutX(startingX);
|
||||
super.setLayoutY(startingY);
|
||||
Arc arc;
|
||||
for (int i = 0; i < numWakes; i++) {
|
||||
arc = new Arc(
|
||||
0,
|
||||
0,
|
||||
30 + RADIUS_INCREASE * i,
|
||||
30 + RADIUS_INCREASE * i,
|
||||
-110,
|
||||
40
|
||||
);
|
||||
arc.setFill(new Color(0.18, 0.7, 1.0, 0.50 + OPACITY_INCREASE * i));
|
||||
arc.setType(ArcType.ROUND);
|
||||
arcs[i] = arc;
|
||||
}
|
||||
super.getChildren().addAll(arcs);
|
||||
}
|
||||
|
||||
boolean updatePosition (double timeInterval) {
|
||||
lifespan--;
|
||||
//super.setOpacity(LIFESPAN_PER_FRAME * lifespan * super.getOpacity());
|
||||
//opacity = LIFESPAN_PER_FRAME * lifespan * opacity;
|
||||
//super.setFill(new Color(0.0f, 0.0f, 1.0f, opacity));
|
||||
super.setLayoutX(super.getLayoutX() + velocityX * timeInterval);
|
||||
super.setLayoutY(super.getLayoutY() + velocityY * timeInterval);
|
||||
super.setStartAngle(super.getStartAngle() - LENGTH_PER_FRAME);
|
||||
super.setLength(super.getLength() + LENGTH_PER_FRAME * 2);
|
||||
return lifespan < 0;
|
||||
/**
|
||||
* Sets the rotationalVelocity of each arc. Each arc is 3 velocities behind the next smallest arc. The smallest uses
|
||||
* the latest given velocity.
|
||||
* @param rotationalVelocity The rotationalVelocity the wake should move at.
|
||||
*/
|
||||
void setRotationalVelocity (double rotationalVelocity) {
|
||||
velocitiesIndex = (velocitiesIndex + 1) % 14;
|
||||
velocities[velocitiesIndex] = rotationalVelocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Arcs rotate based on the distance they would have travelled over the supplied time interval.
|
||||
* @param timeInterval the time interval, in microseconds, that the wake should move.
|
||||
*/
|
||||
void updatePosition (long timeInterval) {
|
||||
int temp = velocitiesIndex;
|
||||
for (int i = 0; i < arcs.length; i++) {
|
||||
//temp = ((temp + 3) % 14);
|
||||
rotations[i] = rotations[i] + velocities[temp] * timeInterval;
|
||||
int j = 0;
|
||||
//I have no idea why I have to do this to make it work.
|
||||
//I will buy you a block of chocolate if you can tell me why.
|
||||
switch (i) {
|
||||
case 4:
|
||||
j = 1; break;
|
||||
case 3:
|
||||
j = 2; break;
|
||||
case 2:
|
||||
j = 3; break;
|
||||
case 1:
|
||||
j = 4; break;
|
||||
}
|
||||
arcs[j].getTransforms().setAll(new Rotate(rotations[i]));
|
||||
temp = ((temp + 3) % 14);
|
||||
}
|
||||
}
|
||||
|
||||
void rotate (double rotation) {
|
||||
for (int i = 0; i < arcs.length; i++) {
|
||||
rotations[i] = rotation;
|
||||
arcs[i].getTransforms().setAll(new Rotate(rotation));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user