import com.nolimitscoaster.*;
import nlvm.math3d.*;
/**
adapter par [email protected] Un script pour Multi Trigger le long du rail avec un exemple de
déclenchement de 2 musiques differentes..
Un exemple avec 3 triggers.........
*/
public class MultiTriggerMusic extends Script implements TrackTriggerListener{
private static final String scriptName = "MultiTriggerMusic";
// .................................definition des 3 triggers..................................
private TrackTrigger Trigger1;
private TrackTrigger Trigger2;
private TrackTrigger Trigger3;
//*********************************definition des 2 musiques**********************************
private static final String sSoundFile1 = "Moon Lifter.ogg";
StaticSound sSound1;
private static final String sSoundFile2 = "SleepAway.ogg";
StaticSound sSound2;
//***************************************************************************************************
public bool onInit(){
Coaster coaster = sim.getCoasterForEntityId(getParentEntityId());
//...................................recherche des triggers sur les rails.................................
Trigger1 = coaster.getTrackTrigger("TestTrigger1");
Trigger1.addTrackTriggerListener(this);
Trigger2 = coaster.getTrackTrigger("TestTrigger2");
Trigger2.addTrackTriggerListener(this);
Trigger3 = coaster.getTrackTrigger("TestTrigger3");
Trigger3.addTrackTriggerListener(this);
//============================================On charge les 2 musiques =======================================
sSound1 = StaticSound.loadFromFile(sSoundFile1, StaticSound.E_ENVMODE_LOCAL);
sSound2 = StaticSound.loadFromFile(sSoundFile2, StaticSound.E_ENVMODE_LOCAL);
return true;
}
//-----------------------------------------------------------------------------------------
public void onNextFrame(float fTickTime)
{
}
public void onTrainEntering(TrackTrigger trigger, Train train)
{
if (trigger == Trigger1)
{
if (train.getSpeed() > 0){
outAction1();
}
}
if (trigger == Trigger2){
if (train.getSpeed() > 0)
{
outAction2();
}
}
if (trigger == Trigger3)
{
if (train.getSpeed() > 0)
{
outAction3();
}
}
}
//-------------------------------------------------------------------------------------------
public void onTrainLeaving(TrackTrigger trigger, Train train)
{
}
//------------------------------------------------------------------------------------------
public void outAction1 ()
{
System.out.println("Entré: Trigger1");
soundTrigger1();
sSound2.stop(); // stop musique 2
sSound1.play(); // play musique 1
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public void outAction2 ()
{
System.out.println("Entré: Trigger2");
sSound1.stop(); // stop musique 1
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public void outAction3 ()
{
System.out.println("Entré: Trigger3");
soundTrigger2();
sSound2.play(); // play musique 2
}
//+++++++++++++++++++++++++++++++++++++++Position de la 1 musique ++++++++++++++++++++++++++++++++++++++
public void soundTrigger1()
{
if(sSound1 == null)
{
System.err.println("Sound file not found");
return;
}
sSound1.setPosition(new Vector3f(0.0f,0.0f,0.0f));
sSound1.setGain(20.0f);
}
//.........................................Position de la 2 musique...................................
public void soundTrigger2()
{
if(sSound2 == null)
{
System.err.println("Sound file not found");
return;
}
sSound2.setPosition(new Vector3f(0.0f,1.0f,0.0f));
sSound2.setGain(20.0f);
}
//...........................................................................................
}