Guest User

Untitled

a guest
May 26th, 2017
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.83 KB | None | 0 0
  1. import com.nolimitscoaster.*;
  2. import nlvm.math3d.*;
  3.  
  4. public class CarHandler implements TrackTriggerListener {
  5.    
  6.     private CarScript mainScript;
  7.     private Simulator sim;
  8.     private Coaster coaster;
  9.     private Train train;
  10.     private int carID;
  11.     private SceneObject sco;
  12.    
  13.     private CarAction actions[];
  14.     private int actionAmount;
  15.     private int currentAction;
  16.    
  17.     private Matrix4x4f trainMatrix;
  18.    
  19.     //Action triggers
  20.     private String action1TriggerName = "action1";
  21.     private String action2TriggerName = "action2";
  22.     private TrackTrigger action1Trigger;
  23.     private TrackTrigger action2Trigger;
  24.    
  25.     //Animation directions
  26.     private final int LEFT = 0;
  27.     private final int RIGHT = 1;
  28.     private final int FRONT = 2;
  29.     private final int BACK = 3;
  30.    
  31.     public CarHandler(CarScript mainScript, Simulator sim, Coaster coaster, Train train, int carID) {
  32.         this.mainScript = mainScript;
  33.         this.sim = sim;
  34.         this.coaster = coaster;
  35.         this.train = train;
  36.         this.carID = carID;
  37.        
  38.         actionAmount = 2;
  39.         currentAction = 0;
  40.        
  41.         trainMatrix = new Matrix4x4f();
  42.        
  43.         sco = sim.getSceneObject("car" + carID);
  44.         if (sco == null) {
  45.             System.err.println("CarHandler: Can't find scene object car" + carID + "!");
  46.             return;
  47.         }
  48.        
  49.         action1Trigger = coaster.getTrackTrigger(action1TriggerName);
  50.         if (action1Trigger == null) {
  51.             System.err.println("CarHandler: Can't find trigger " + action1TriggerName + "!");
  52.             return;
  53.         }
  54.         action1Trigger.addTrackTriggerListener(this);
  55.        
  56.         action2Trigger = coaster.getTrackTrigger(action2TriggerName);
  57.         if (action2Trigger == null) {
  58.             System.err.println("CarHandler: Can't find trigger " + action2TriggerName + "!");
  59.             return;
  60.         }
  61.         action2Trigger.addTrackTriggerListener(this);
  62.     }
  63.    
  64.     public void process(float tick) {
  65.         train.getCarMatrix(0, trainMatrix);
  66.         sco.setMatrix(trainMatrix);
  67.        
  68.         if (actions == null) {
  69.             return;
  70.         }
  71.        
  72.         for (int i = 0; i < actionAmount; i++) {
  73.             if (actions[i] != null) {
  74.                 actions[i].process(tick);
  75.             }
  76.         }
  77.     }
  78.    
  79.     public void start() {
  80.         actions = new CarAction[actionAmount];
  81.     }
  82.    
  83.     public void stop() {
  84.         actions = null;
  85.         currentAction = 0;
  86.     }
  87.    
  88.     public Train getTrain() {
  89.         return train;
  90.     }
  91.    
  92.     public Simulator getSim() {
  93.         return sim;
  94.     }
  95.    
  96.     public SceneObject getSco() {
  97.         return sco;
  98.     }
  99.    
  100.     public void onTrainEntering(TrackTrigger trigger, Train train) {
  101.         if (train != this.train) {
  102.             return;
  103.         }
  104.         if (trigger == action1Trigger) {
  105.             if (actions == null) {
  106.                 start();
  107.             }
  108.            
  109.             actions[currentAction] = new CarAction(this, sim.getCurAbsSimulationTimeSec(), 3.f, LEFT);
  110.             currentAction++;
  111.         }
  112.        
  113.         if (trigger == action2Trigger) {
  114.             actions[currentAction] = new CarAction(this, sim.getCurAbsSimulationTimeSec(), 3.f, RIGHT);
  115.             currentAction++;
  116.         }
  117.     }
  118.    
  119.     public void onTrainLeaving(TrackTrigger trigger, Train train) {
  120.        
  121.     }
  122. }
Add Comment
Please, Sign In to add comment