Warning sound added. Sound synced with visual display. #story[1292]
This commit is contained in:
@@ -25,7 +25,6 @@ import javafx.scene.paint.Material;
|
|||||||
import javafx.scene.paint.PhongMaterial;
|
import javafx.scene.paint.PhongMaterial;
|
||||||
import javafx.scene.shape.MeshView;
|
import javafx.scene.shape.MeshView;
|
||||||
import javafx.scene.shape.Shape3D;
|
import javafx.scene.shape.Shape3D;
|
||||||
import javafx.scene.transform.Rotate;
|
|
||||||
import javafx.scene.transform.Translate;
|
import javafx.scene.transform.Translate;
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
import network.Messages.Enums.RaceStatusEnum;
|
import network.Messages.Enums.RaceStatusEnum;
|
||||||
@@ -72,7 +71,7 @@ public class RaceViewController extends Controller {
|
|||||||
private int heartbeatDelay = 1000;
|
private int heartbeatDelay = 1000;
|
||||||
private long heartbeatTime = 0;
|
private long heartbeatTime = 0;
|
||||||
private GPSConverter gpsConverter;
|
private GPSConverter gpsConverter;
|
||||||
private ArrayList<FireParticle> fireParticleList = new ArrayList<>();
|
private ArrayList<HealthEffect> healthEffectList = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -350,10 +349,10 @@ public class RaceViewController extends Controller {
|
|||||||
|
|
||||||
|
|
||||||
//Create first fire
|
//Create first fire
|
||||||
FireParticle fire = new FireParticle(boat.getSourceID(), System.currentTimeMillis());
|
HealthEffect fire = new HealthEffect(boat.getSourceID(), System.currentTimeMillis());
|
||||||
viewSubjects.add(fire);
|
viewSubjects.add(fire);
|
||||||
//fire.setVisible(false);
|
//fire.setVisible(false);
|
||||||
fireParticleList.add(fire);
|
healthEffectList.add(fire);
|
||||||
|
|
||||||
|
|
||||||
//fire.rotateView((double) 90, fire.getPosition().getX(), fire.getPosition().getY(), fire.getPosition().getZ(), Rotate.X_AXIS);
|
//fire.rotateView((double) 90, fire.getPosition().getX(), fire.getPosition().getY(), fire.getPosition().getZ(), Rotate.X_AXIS);
|
||||||
@@ -698,11 +697,15 @@ public class RaceViewController extends Controller {
|
|||||||
stop(); // stop the timer
|
stop(); // stop the timer
|
||||||
} else {
|
} else {
|
||||||
for(VisualiserBoat boat : raceState.getBoats()){
|
for(VisualiserBoat boat : raceState.getBoats()){
|
||||||
for (FireParticle fp : fireParticleList){
|
for (HealthEffect fp : healthEffectList){
|
||||||
if(fp.getSourceID()==boat.getSourceID()){
|
if(fp.getSourceID()==boat.getSourceID()){
|
||||||
|
if(boat.getHealth()<=10){
|
||||||
|
fp.flash(System.currentTimeMillis(), 300, boat.getSourceID()==raceState.getPlayerBoatID());
|
||||||
|
}
|
||||||
|
else
|
||||||
if(boat.getHealth()<=20) {
|
if(boat.getHealth()<=20) {
|
||||||
//fp.setVisible(true);
|
//fp.setVisible(true);
|
||||||
fp.flash(System.currentTimeMillis(), 200);
|
fp.flash(System.currentTimeMillis(), 500, boat.getSourceID()==raceState.getPlayerBoatID());
|
||||||
} else {
|
} else {
|
||||||
fp.setVisible(false);
|
fp.setVisible(false);
|
||||||
}
|
}
|
||||||
@@ -710,24 +713,25 @@ public class RaceViewController extends Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
// try {
|
||||||
if(raceState.getBoat(raceState.getPlayerBoatID()).getHealth()<=20){
|
// if(raceState.getBoat(raceState.getPlayerBoatID()).getHealth()<=10){
|
||||||
heartbeatDelay = 500;
|
// heartbeatDelay = 300;
|
||||||
} else if (raceState.getBoat(raceState.getPlayerBoatID()).getHealth()<=40){
|
// } else if (raceState.getBoat(raceState.getPlayerBoatID()).getHealth()<=20){
|
||||||
heartbeatDelay = 1000;
|
// heartbeatDelay = 500;
|
||||||
}
|
// }
|
||||||
if(raceState.getBoat(raceState.getPlayerBoatID()).getHealth()<=40){
|
// if(raceState.getBoat(raceState.getPlayerBoatID()).getHealth()<=20){
|
||||||
|
//
|
||||||
//imageView.translateXProperty().setValue(raceState.getBoat(raceState.getPlayerBoatID()).getPosition().getLongitude());
|
// //imageView.translateXProperty().setValue(raceState.getBoat(raceState.getPlayerBoatID()).getPosition().getLongitude());
|
||||||
if(System.currentTimeMillis() > heartbeatTime+heartbeatDelay) {
|
// if(System.currentTimeMillis() > heartbeatTime+heartbeatDelay) {
|
||||||
AudioClip sound = new AudioClip(this.getClass().getResource("/visualiser/sounds/heartbeat.mp3").toExternalForm());
|
// AudioClip sound = new AudioClip(this.getClass().getResource("/visualiser/sounds/warning.mp3").toExternalForm());
|
||||||
sound.play();
|
// sound.setVolume(0.3);
|
||||||
heartbeatTime = System.currentTimeMillis() + heartbeatDelay;
|
// sound.play();
|
||||||
}
|
// heartbeatTime = System.currentTimeMillis() + heartbeatDelay;
|
||||||
}
|
// }
|
||||||
} catch (BoatNotFoundException e) {
|
// }
|
||||||
e.printStackTrace();
|
// } catch (BoatNotFoundException e) {
|
||||||
}
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
|
|||||||
+27
-16
@@ -2,49 +2,51 @@ package visualiser.layout;
|
|||||||
|
|
||||||
import javafx.geometry.Point3D;
|
import javafx.geometry.Point3D;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.scene.media.AudioClip;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.paint.Material;
|
|
||||||
import javafx.scene.paint.PhongMaterial;
|
import javafx.scene.paint.PhongMaterial;
|
||||||
import javafx.scene.shape.*;
|
import javafx.scene.shape.*;
|
||||||
import javafx.scene.transform.Rotate;
|
import javafx.scene.transform.Rotate;
|
||||||
import javafx.scene.transform.Translate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by zwu18 on 24/09/17.
|
* Created by zwu18 on 24/09/17.
|
||||||
*/
|
*/
|
||||||
public class FireParticle extends Subject3D {
|
public class HealthEffect extends Subject3D {
|
||||||
|
|
||||||
private int sourceID;
|
private int sourceID;
|
||||||
private long currentTime;
|
private long currentTime;
|
||||||
private long flashInterval;
|
private long flashInterval;
|
||||||
|
private AudioClip sound = new AudioClip(this.getClass().getResource("/visualiser/sounds/warning.mp3").toExternalForm());
|
||||||
|
|
||||||
public FireParticle(int sourceID, long currentTime){
|
public HealthEffect(int sourceID, long currentTime){
|
||||||
super(createFire(), 0);
|
super(createEffect(), 0);
|
||||||
this.sourceID = sourceID;
|
this.sourceID = sourceID;
|
||||||
this.currentTime = currentTime;
|
this.currentTime = currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Shape3D createFire(){
|
/**
|
||||||
|
* Initialise the mesh view with image
|
||||||
Image fire = new Image(FireParticle.class.getClassLoader().getResourceAsStream("images/warning.png"));
|
* @return Mesh view
|
||||||
|
*/
|
||||||
|
private static Shape3D createEffect(){
|
||||||
|
|
||||||
|
Image image = new Image(HealthEffect.class.getClassLoader().getResourceAsStream("images/warning.png"));
|
||||||
|
|
||||||
Plane3D plane = new Plane3D(20, 20, 10, 10);
|
Plane3D plane = new Plane3D(20, 20, 10, 10);
|
||||||
|
|
||||||
PhongMaterial material = new PhongMaterial();
|
PhongMaterial material = new PhongMaterial();
|
||||||
material.setDiffuseColor(Color.web("#FFFFFF"));
|
material.setDiffuseColor(Color.web("#FFFFFF"));
|
||||||
material.setSpecularColor(Color.web("#000000"));
|
material.setSpecularColor(Color.web("#000000"));
|
||||||
material.setDiffuseMap(fire);
|
material.setDiffuseMap(image);
|
||||||
|
|
||||||
MeshView fireSurface = new MeshView(plane);
|
MeshView imageSurface = new MeshView(plane);
|
||||||
|
|
||||||
|
|
||||||
fireSurface.setMaterial(material);
|
imageSurface.setMaterial(material);
|
||||||
fireSurface.setMouseTransparent(true);
|
imageSurface.setMouseTransparent(true);
|
||||||
//fireSurface.toFront(); this.flashInterval = flashInterval;
|
//imageSurface.toFront(); this.flashInterval = flashInterval;
|
||||||
|
|
||||||
return fireSurface;
|
return imageSurface;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rotateView(Double angle, Double pivotX, Double pivotY, Double pivotZ, Point3D axis){
|
public void rotateView(Double angle, Double pivotX, Double pivotY, Double pivotZ, Point3D axis){
|
||||||
@@ -64,12 +66,21 @@ public class FireParticle extends Subject3D {
|
|||||||
return sourceID;
|
return sourceID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flash(long checkTime, long flashInterval){
|
/**
|
||||||
|
* Flash the mesh view at a certain interval
|
||||||
|
* @param checkTime The current time of flash
|
||||||
|
* @param flashInterval Desired flash interval
|
||||||
|
*/
|
||||||
|
public void flash(long checkTime, long flashInterval, boolean playerBoat){
|
||||||
if(checkTime >= (currentTime+flashInterval)){
|
if(checkTime >= (currentTime+flashInterval)){
|
||||||
this.currentTime = checkTime;
|
this.currentTime = checkTime;
|
||||||
if(this.getMesh().isVisible()){
|
if(this.getMesh().isVisible()){
|
||||||
this.setVisible(false);
|
this.setVisible(false);
|
||||||
} else {
|
} else {
|
||||||
|
if(playerBoat) {
|
||||||
|
sound.setVolume(0.1);
|
||||||
|
sound.play();
|
||||||
|
}
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
Reference in New Issue
Block a user