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