Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.nolimitscoaster.*;
- import nlvm.math3d.*;
- public class CarHandler implements TrackTriggerListener {
- private CarScript mainScript;
- private Simulator sim;
- private Coaster coaster;
- private Train train;
- private int carID;
- private SceneObject sco;
- private CarAction actions[];
- private int actionAmount;
- private int currentAction;
- private Matrix4x4f trainMatrix;
- //Action triggers
- private String action1TriggerName = "action1";
- private String action2TriggerName = "action2";
- private TrackTrigger action1Trigger;
- private TrackTrigger action2Trigger;
- //Animation directions
- private final int LEFT = 0;
- private final int RIGHT = 1;
- private final int FRONT = 2;
- private final int BACK = 3;
- public CarHandler(CarScript mainScript, Simulator sim, Coaster coaster, Train train, int carID) {
- this.mainScript = mainScript;
- this.sim = sim;
- this.coaster = coaster;
- this.train = train;
- this.carID = carID;
- actionAmount = 2;
- currentAction = 0;
- trainMatrix = new Matrix4x4f();
- sco = sim.getSceneObject("car" + carID);
- if (sco == null) {
- System.err.println("CarHandler: Can't find scene object car" + carID + "!");
- return;
- }
- action1Trigger = coaster.getTrackTrigger(action1TriggerName);
- if (action1Trigger == null) {
- System.err.println("CarHandler: Can't find trigger " + action1TriggerName + "!");
- return;
- }
- action1Trigger.addTrackTriggerListener(this);
- action2Trigger = coaster.getTrackTrigger(action2TriggerName);
- if (action2Trigger == null) {
- System.err.println("CarHandler: Can't find trigger " + action2TriggerName + "!");
- return;
- }
- action2Trigger.addTrackTriggerListener(this);
- }
- public void process(float tick) {
- train.getCarMatrix(0, trainMatrix);
- sco.setMatrix(trainMatrix);
- if (actions == null) {
- return;
- }
- for (int i = 0; i < actionAmount; i++) {
- if (actions[i] != null) {
- actions[i].process(tick);
- }
- }
- }
- public void start() {
- actions = new CarAction[actionAmount];
- }
- public void stop() {
- actions = null;
- currentAction = 0;
- }
- public Train getTrain() {
- return train;
- }
- public Simulator getSim() {
- return sim;
- }
- public SceneObject getSco() {
- return sco;
- }
- public void onTrainEntering(TrackTrigger trigger, Train train) {
- if (train != this.train) {
- return;
- }
- if (trigger == action1Trigger) {
- if (actions == null) {
- start();
- }
- actions[currentAction] = new CarAction(this, sim.getCurAbsSimulationTimeSec(), 3.f, LEFT);
- currentAction++;
- }
- if (trigger == action2Trigger) {
- actions[currentAction] = new CarAction(this, sim.getCurAbsSimulationTimeSec(), 3.f, RIGHT);
- currentAction++;
- }
- }
- public void onTrainLeaving(TrackTrigger trigger, Train train) {
- }
- }
Add Comment
Please, Sign In to add comment