Boat now shows a fading collision effect
#story[1195]
This commit is contained in:
@@ -21,10 +21,7 @@ import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Material;
|
||||
import javafx.scene.paint.PhongMaterial;
|
||||
import javafx.scene.shape.Box;
|
||||
import javafx.scene.shape.MeshView;
|
||||
import javafx.scene.shape.Shape3D;
|
||||
import javafx.scene.shape.Sphere;
|
||||
import javafx.scene.shape.*;
|
||||
import javafx.scene.transform.Translate;
|
||||
import javafx.util.Callback;
|
||||
import network.Messages.Enums.RaceStatusEnum;
|
||||
@@ -309,9 +306,12 @@ public class RaceController extends Controller {
|
||||
if(nextMark.getMark2() != null) {
|
||||
view3D.getShape(nextMark.getMark2().getSourceID()).setMaterial(markColor);
|
||||
}
|
||||
Subject3D shockwave = new Shockwave();
|
||||
|
||||
viewSubjects.add(shockwave);
|
||||
|
||||
boat.legProperty().addListener((o, prev, curr) -> swapColours(curr));
|
||||
boat.hasCollidedProperty().addListener((o, prev, curr) -> showCollision(boat));
|
||||
boat.hasCollidedProperty().addListener((o, prev, curr) -> showCollision(boatModel, shockwave));
|
||||
}
|
||||
// Fix initial bird's-eye position
|
||||
view3D.updatePivot(new Translate(250, 0, 210));
|
||||
@@ -369,8 +369,24 @@ public class RaceController extends Controller {
|
||||
});
|
||||
}
|
||||
|
||||
private void showCollision(VisualiserBoat boat) {
|
||||
System.out.println(boat.getSourceID() + " has collided");
|
||||
private void showCollision(Subject3D boat, Subject3D shockwave) {
|
||||
AnimationTimer shockFront = new AnimationTimer() {
|
||||
double opacity = 1;
|
||||
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
shockwave.setX(boat.getPosition().getX());
|
||||
shockwave.setY(boat.getPosition().getY());
|
||||
shockwave.setZ(boat.getPosition().getZ());
|
||||
|
||||
if(opacity <= 0) this.stop();
|
||||
else {
|
||||
shockwave.getMesh().setMaterial(new PhongMaterial(new Color(1,0,0,opacity)));
|
||||
opacity -= 0.1;
|
||||
}
|
||||
}
|
||||
};
|
||||
shockFront.start();
|
||||
}
|
||||
|
||||
private void addThirdPersonAnnotations(Subject3D subject3D) {
|
||||
|
||||
Reference in New Issue
Block a user