From 5fd5a3bd54a5e5ea78f9fbd40e69f1efac2b54f3 Mon Sep 17 00:00:00 2001 From: zwu18 Date: Mon, 9 Oct 2017 01:31:22 +1300 Subject: [PATCH] Improved finish display. --- .../Controllers/RaceFinishController.java | 107 +++++++++++++ .../visualiser/scenes/gameLobby.fxml | 149 +++++++++--------- .../visualiser/scenes/raceFinish.fxml | 91 +++++++---- 3 files changed, 240 insertions(+), 107 deletions(-) diff --git a/racevisionGame/src/main/java/visualiser/Controllers/RaceFinishController.java b/racevisionGame/src/main/java/visualiser/Controllers/RaceFinishController.java index 29d2b290..933d9489 100644 --- a/racevisionGame/src/main/java/visualiser/Controllers/RaceFinishController.java +++ b/racevisionGame/src/main/java/visualiser/Controllers/RaceFinishController.java @@ -1,12 +1,29 @@ package visualiser.Controllers; +import com.interactivemesh.jfx.importer.stl.StlMeshImporter; +import javafx.animation.AnimationTimer; +import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXML; +import javafx.scene.AmbientLight; +import javafx.scene.PointLight; import javafx.scene.control.Label; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; +import javafx.scene.layout.GridPane; +import javafx.scene.media.AudioClip; +import javafx.scene.paint.Color; +import javafx.scene.paint.Material; +import javafx.scene.paint.PhongMaterial; +import javafx.scene.shape.MeshView; +import javafx.scene.shape.Shape3D; +import visualiser.app.App; +import visualiser.layout.*; import visualiser.model.VisualiserBoat; +import java.io.IOException; +import java.net.URL; + /** * Finish Screen for when the race finishes. */ @@ -15,12 +32,94 @@ public class RaceFinishController extends Controller { private @FXML TableColumn boatRankColumn; private @FXML TableColumn boatNameColumn; private @FXML Label raceWinnerLabel; + private @FXML GridPane animatedPane; + private SkyBox skyBox; + private SeaSurface seaSurface; + private Subject3D boat; + private AmbientLight ambientLight; + private Subject3D sailsSubject; + private ObservableList subjects = FXCollections.observableArrayList(); /** * Display the table * @param boats boats to display on the table. */ public void loadFinish(ObservableList boats) { + + ambientLight = new AmbientLight(Color.web("#CCCCFF")); + ambientLight.setTranslateX(250); + ambientLight.setTranslateZ(210); + ambientLight.setLightOn(true); + + if (!App.dayMode) ambientLight.setColor(Color.web("#9999AA")); + + PointLight pointLight = new PointLight(Color.web("#AAAAFF")); + pointLight.setTranslateX(250); + pointLight.setTranslateZ(210); + pointLight.setLightOn(true); + + View3D view3D = new View3D(); + view3D.addAmbientLight(ambientLight); + view3D.addPointLight(pointLight); + view3D.setDistance(10); + view3D.setPitch(5); + view3D.setItems(subjects); + +// URL asset = RaceViewController.class.getClassLoader().getResource("assets/V1.2 Complete Boat.stl"); +// StlMeshImporter importer = new StlMeshImporter(); +// importer.read(asset); +// Subject3D boat = new Subject3D(new MeshView(importer.getImport()), 0); + + Shape3D mesh = Assets3D.getBoat(); + boat = new Subject3D(mesh, 0); + + skyBox = new SkyBox(750,200,250,0,250); + subjects.addAll(skyBox.getSkyBoxPlanes()); + + seaSurface = new SeaSurface(750, 200); + seaSurface.setX(250); + seaSurface.setZ(250); + subjects.add(seaSurface); + + double radius = 100; + boat.setX(0); + boat.setZ(radius); + boat.setScale(0.1); + + subjects.add(boat); + view3D.trackSubject(boat, -45); + + //add sail + Material whiteSail = new PhongMaterial(Color.WHITE); + Sails3D sails3D = new Sails3D(); + sailsSubject = new Subject3D(sails3D, 0); + sails3D.setMouseTransparent(true); + sails3D.setMaterial(whiteSail); + sailsSubject.setXRot(0d); + sailsSubject.setX(0); + sailsSubject.setZ(radius); + sailsSubject.setScale(0.1); + subjects.add(sailsSubject); + + animatedPane.add(view3D, 0, 0); + + AnimationTimer loop = new AnimationTimer() { + double angle = -90; + double offset = 0.05; + @Override + public void handle(long now) { + boat.setX(radius * Math.cos(angle * Math.PI/180)); + boat.setZ(radius * Math.sin(angle * Math.PI/180)); + boat.setHeading(-angle); + sailsSubject.setX(boat.getX()); + sailsSubject.setZ(boat.getZ()); + sailsSubject.setHeading(boat.getHeading().getAngle()); + angle += offset; + } + }; + loop.start(); + + // set table contents boatInfoTable.setItems(boats); //Name. @@ -36,4 +135,12 @@ public class RaceFinishController extends Controller { } } + public void mainMenuPressed() throws IOException { + AudioClip sound = new AudioClip(this.getClass().getResource("/visualiser/sounds/buttonpress.wav").toExternalForm()); + sound.play(); + App.game.endEvent(); + loadTitleScreen(); + } + + } diff --git a/racevisionGame/src/main/resources/visualiser/scenes/gameLobby.fxml b/racevisionGame/src/main/resources/visualiser/scenes/gameLobby.fxml index fb153817..d8911671 100644 --- a/racevisionGame/src/main/resources/visualiser/scenes/gameLobby.fxml +++ b/racevisionGame/src/main/resources/visualiser/scenes/gameLobby.fxml @@ -22,88 +22,93 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + - + diff --git a/racevisionGame/src/main/resources/visualiser/scenes/raceFinish.fxml b/racevisionGame/src/main/resources/visualiser/scenes/raceFinish.fxml index c92fa7c8..f17a2ae5 100644 --- a/racevisionGame/src/main/resources/visualiser/scenes/raceFinish.fxml +++ b/racevisionGame/src/main/resources/visualiser/scenes/raceFinish.fxml @@ -1,5 +1,9 @@ + + + + @@ -9,41 +13,58 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + +