Advertisement
Guest User

Untitled

a guest
Jul 4th, 2016
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.22 KB | None | 0 0
  1. import com.nolimitscoaster.*;
  2. import nlvm.math3d.*;
  3.  
  4. public class Speaker11 extends Script implements TrackTriggerListener {
  5.     private static final float xOffset = 0;
  6.     private static final float yOffset = 0;
  7.     private static final float zOffset = 1.1f;
  8.     private static final int carToAttach = 0;
  9.     private static final int trainToAttach = 0;
  10.    
  11.     private Coaster coaster;
  12.     private Train train;
  13.     private SceneObject sco;
  14.     private Vector3f posOut = new Vector3f(0, 0, 0);
  15.     private Vector3f pitchHeadBankOut = new Vector3f(0, 0, 0);
  16.     private Matrix4x4f carMatrix = new Matrix4x4f();
  17.    
  18.     private TrackTrigger musicDispatchTrigger;
  19.     private TrackTrigger musicLaunchFrontTrigger;
  20.     private TrackTrigger musicLaunchBackwardsTrigger;
  21.     private TrackTrigger musicLaunchResetTrigger;
  22.    
  23.     private bool launchFront = false;
  24.     private bool launchBackwards = false;
  25.     private bool launchReady = false;
  26.    
  27.     private static final String nameLaunchIdleAudio = "onboard10.ogg";
  28.     private static final String nameDispatchAudio = "onboard11.ogg";
  29.     private static final String nameTrackAudio = "onboard12.ogg";
  30.    
  31.     private float volume = 20.0f;
  32.     private float distance = 5.0f;
  33.    
  34.     private StaticSound dispatchSound;
  35.     private StaticSound trackSound;
  36.     private StaticSound idleSound;
  37.    
  38.     public bool onInit() {
  39.         coaster = sim.getCoaster("Rock n Roller Coaster");
  40.         if (coaster == null) {
  41.             System.err.println("Speakers: Coaster not found.");
  42.             return false;
  43.         }
  44.        
  45.         sco = sim.getSceneObjectForEntityId(getParentEntityId());
  46.         if (sco == null) {
  47.             System.err.println("Speakers: Object not found.");
  48.             return false;
  49.         }
  50.        
  51.         train = coaster.getTrainAt(trainToAttach);
  52.         if (train == null) {
  53.             System.err.println("Speakers: Train not found.");
  54.             return false;
  55.         }
  56.        
  57.         musicDispatchTrigger = coaster.getTrackTrigger("MusicDispatch");
  58.         if (musicDispatchTrigger == null) {
  59.             System.err.println("Speakers: Trigger not found.");
  60.             return false;
  61.         }
  62.         musicDispatchTrigger.addTrackTriggerListener(this);
  63.        
  64.         musicLaunchFrontTrigger = coaster.getTrackTrigger("MusicLaunchFront");
  65.         if (musicLaunchFrontTrigger == null) {
  66.             System.err.println("Speakers: Trigger not found.");
  67.             return false;
  68.         }
  69.         musicLaunchFrontTrigger.addTrackTriggerListener(this);
  70.        
  71.         musicLaunchBackwardsTrigger = coaster.getTrackTrigger("MusicLaunchBackwards");
  72.         if (musicLaunchBackwardsTrigger == null) {
  73.             System.err.println("Speakers: Trigger not found.");
  74.             return false;
  75.         }
  76.         musicLaunchBackwardsTrigger.addTrackTriggerListener(this);
  77.        
  78.         musicLaunchResetTrigger = coaster.getTrackTrigger("MusicLaunchReset");
  79.         if (musicLaunchResetTrigger == null) {
  80.             System.err.println("Speakers: Trigger not found.");
  81.             return false;
  82.         }
  83.         musicLaunchResetTrigger.addTrackTriggerListener(this);
  84.        
  85.         dispatchSound = StaticSound.loadFromFile(nameDispatchAudio, 0);
  86.         if (dispatchSound == null) {
  87.             System.err.println("Speakers: File not found.");
  88.             return false;
  89.         }
  90.         dispatchSound.setGain(volume);
  91.         dispatchSound.setDistanceParameters(distance, 1.0f);
  92.        
  93.         trackSound = StaticSound.loadFromFile(nameTrackAudio, 0);
  94.         if (dispatchSound == null) {
  95.             System.err.println("Speakers: File not found.");
  96.             return false;
  97.         }
  98.         trackSound.setGain(volume);
  99.         trackSound.setDistanceParameters(distance, 1.0f);
  100.        
  101.         idleSound = StaticSound.loadFromFile(nameLaunchIdleAudio, 0);
  102.         if (idleSound == null) {
  103.             System.err.println("Speakers: File not found.");
  104.             return false;
  105.         }
  106.         idleSound.setGain(volume);
  107.         idleSound.setDistanceParameters(distance, 1.0f);
  108.        
  109.         setElements(sco, false);
  110.        
  111.         return true;
  112.     }
  113.    
  114.     public void onNextFrame(float tick) {
  115.         train.getCarMatrix(carToAttach, carMatrix);
  116.        
  117.         Tools.matrixToPitchHeadBankPos(carMatrix, pitchHeadBankOut, posOut);
  118.        
  119.         Matrix4x4f matrix = new Matrix4x4f();
  120.         matrix.initTrans(xOffset, yOffset, zOffset);
  121.         carMatrix.multRight(matrix);
  122.        
  123.         Tools.matrixToPitchHeadBankPos(carMatrix, pitchHeadBankOut, posOut);
  124.         sco.setRotation(pitchHeadBankOut);
  125.         sco.setTranslation(posOut);
  126.        
  127.         dispatchSound.setPosition(sco.getTranslation());
  128.         trackSound.setPosition(sco.getTranslation());
  129.         idleSound.setPosition(sco.getTranslation());
  130.     }
  131.    
  132.     public void setElements(SceneObject sco, bool visible) {
  133.         int n = sco.getElementCount();
  134.         for (int i = n - 1; i >= 0; i--) {
  135.             sco.getElementAt(i).setVisible(visible);
  136.         }
  137.     }
  138.    
  139.     public void playDispatch() {
  140.         dispatchSound.play();
  141.     }
  142.    
  143.     public void playIdleSound() {
  144.         idleSound.play();
  145.     }
  146.    
  147.     public void playTrackSound() {
  148.         idleSound.stop();
  149.         trackSound.play();
  150.     }
  151.    
  152.     public void onTrainEntering(TrackTrigger trigger, Train trainTrig) {
  153.         if ((trigger == musicDispatchTrigger) && (trainTrig == train)) {
  154.             playDispatch();
  155.         } else if ((trigger == musicLaunchBackwardsTrigger) && (launchFront) && (trainTrig == train)) {
  156.             playTrackSound();
  157.             launchBackwards = true;
  158.             launchReady = true;
  159.         } else if ((trigger == musicLaunchFrontTrigger) && (trainTrig == train)) {
  160.             playIdleSound();
  161.             launchFront = true;
  162.         } else if ((trigger == musicLaunchResetTrigger) && (trainTrig == train)) {
  163.             launchFront = false;
  164.             launchBackwards = false;
  165.             launchReady = false;
  166.         }
  167.     }
  168.    
  169.     public void onTrainLeaving(TrackTrigger trigger, Train trainTrig) {
  170.        
  171.     }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement