You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.2 KiB

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.PhongMaterial;
import javafx.scene.shape.*;
import javafx.scene.transform.Rotate;
/**
* Created by zwu18 on 24/09/17.
*/
public class HealthEffect extends Subject3D {
private int sourceID;
private long currentTime;
private long flashInterval;
private AudioClip warningSound = new AudioClip(this.getClass().getResource("/visualiser/sounds/warning.mp3").toExternalForm());
private AudioClip deadSound = new AudioClip(this.getClass().getResource("/visualiser/sounds/dead1.wav").toExternalForm());
public HealthEffect(int sourceID, long currentTime){
super(createEffect(), 0);
this.sourceID = sourceID;
this.currentTime = currentTime;
}
/**
* 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(image);
MeshView imageSurface = new MeshView(plane);
imageSurface.setMaterial(material);
imageSurface.setMouseTransparent(true);
//imageSurface.toFront(); this.flashInterval = flashInterval;
return imageSurface;
}
public void rotateView(Double angle, Double pivotX, Double pivotY, Double pivotZ, Point3D axis){
Rotate rotate = new Rotate(angle, axis);
rotate.setPivotX(pivotX);
rotate.setPivotY(pivotY);
rotate.setPivotZ(pivotZ);
this.getMesh().getTransforms().add(rotate);
}
public void setVisible(boolean bool){
this.getMesh().setVisible(bool);
}
public int getSourceID(){
return sourceID;
}
public void setSourceID(int id){
this.sourceID = id;
}
public void displayDeath(){
Image image = new Image(HealthEffect.class.getClassLoader().getResourceAsStream("images/warning2.png"));
PhongMaterial material = (PhongMaterial) this.getMesh().getMaterial();
material.setDiffuseColor(Color.web("#FFFFFF"));
material.setSpecularColor(Color.web("#000000"));
material.setDiffuseMap(image);
this.getMesh().setMaterial(material);
deadSound.play();
}
/**
* 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) {
warningSound.setVolume(0.1);
warningSound.play();
}
this.setVisible(true);
}
}
}
}