import com.nolimitscoaster.*;
import nlvm.math3d.*;
// cractéristique des trains
[email protected]
public class ProprieteTrain extends Script implements TrackTriggerListener
{
private SceneObject sco; // definition d'un objet dans la scene
Train fTrain; // definition de la variable train
private int NbTrain;
private static final String scriptName = "ProprieteTrain";
private TrackTrigger Trigger1; // definition trigger 1
private TrackTrigger Trigger2; // definition trigger 2
private static final String sSoundFile1 = "Moon Lifter.ogg"; // 1ere musique definition
StaticSound sSound1;
private Vector3f positionSound ;
public bool onInit()
{
String name; // definition de la variable String name
Coaster coaster = sim.getCoasterForEntityId(getParentEntityId());
if (coaster == null){
System.err.println("This script must be attached to a coaster");
return false;
}
name = coaster.getName();
System.out.println(name); // donne le nom du coaster
fTrain = coaster.getTrainAt(0); // cherche le numero du train 0 = 1er train 1 = 2eme train ...
// Dans la classe coaster
NbTrain = coaster.getTrainCount(); // nombre entier cherche le nombre de trains
System.out.println(NbTrain);
Trigger1 = coaster.getTrackTrigger("startSound1");
Trigger1.addTrackTriggerListener(this);
Trigger2 = coaster.getTrackTrigger("stopSound1");
Trigger2.addTrackTriggerListener(this);
sSound1 = StaticSound.loadFromFile(sSoundFile1, StaticSound.E_ENVMODE_LOCAL);
/**
sco = sim.getSceneObject("LightTest");
if (sco == null)
{
System.err.println(scriptName + ": the script is not part of a scene object"); // on trouve pas le nom
return false;
}
*/
return true;
}
public void onNextFrame(float tick)
{
Vector3f fo = new Vector3f(0.0f, 0.0f, 0.0f);
Vector3f to = new Vector3f(0.0f, 0.0f, 0.0f);
Vector3f ro = new Vector3f(0.0f, 0.0f, 0.0f);
Vector3f po = new Vector3f(0.0f, 0.0f, 0.0f);
fTrain.getCarOrientationAndPosition(1, fo, to, ro, po); // recherche la position du train avec la position du car
positionSound = po;
System.out.println( positionSound);
sSound1.setPosition(positionSound); // definition de l'emission du sound1 suit le train
}
public void onTrainEntering(TrackTrigger trigger, Train train)
{
if (trigger == Trigger1)
{
if (train.getSpeed() > 0)
{
sSound1.setGain(20.0f);
sSound1.play();
}
}
if (trigger == Trigger2)
{
if (train.getSpeed() > 0)
{
sSound1.stop();
}
}
}
public void onTrainLeaving(TrackTrigger trigger, Train train)
{
}
}