Advertisement
Guest User

Untitled

a guest
Mar 25th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package alternativa.tanks.vehicles.tanks
  2. {
  3.     /**
  4.      * ...
  5.      * @author ...
  6.      */
  7. import alternativa.osgi.service.storage.IStorageService;
  8. import alternativa.init.Main;
  9.     public class calculateTrackSpeed
  10.     {
  11.         private static const FORWARD:int = 1;
  12.         private static const BACK:int = 2;
  13.         private static const LEFT:int = 4;
  14.         private static const RIGHT:int = 8;
  15.         private static const TURRET_LEFT:int = 16;
  16.         private static const TURRET_RIGHT:int = 32;
  17.         private static const CENTER_TURRET:int = 64;
  18.         private static const REVERSE_TURN_BIT:int = 128;
  19.         private static const minSpeed:Number = 0.1;
  20.         private static const minASpeed:Number = 0.0001;
  21.         private static var k_V:Number = 0.01;
  22.         private static var k_aV:Number = 2;
  23.         private static var left:Number = 0;
  24.         private static var right:Number = 0;
  25.        
  26.         public function calculateTrackSpeed()
  27.         {
  28.            
  29.         }
  30.    
  31.         public static function calculateLeftTrackSpeed(moduleV:Number, moduleaV:Number, controlbits:int, numContacts:int, numCollision:int,maxSpeed:Number):Number
  32.         {
  33.             k_V = IStorageService(Main.osgi.getService(IStorageService)).getStorage().data["k_V"];//isNaN(Number(Game._kV.value))?0.1:Number(Game._kV.value);
  34.             k_aV = IStorageService(Main.osgi.getService(IStorageService)).getStorage().data["k_AV"];//isNaN( Number(Game._kaV.value))?0.1:Number(Game._kaV.value);
  35.        
  36.             var linearMovementDirection:int = !(controlbits & FORWARD) && !(controlbits & BACK)? 0:!(controlbits & FORWARD) && (controlbits & BACK)? -1:1;
  37.             var angularMovementDirection:int =  !(controlbits & LEFT) && !(controlbits & RIGHT)? 0:!(controlbits & LEFT) && (controlbits & RIGHT)? -1:1;
  38.             var leftTrackSpeed:Number = (linearMovementDirection != 0) && (angularMovementDirection == 0)? linearMovementDirection * k_V * moduleV: ((linearMovementDirection == 0) && (angularMovementDirection != 0))? -angularMovementDirection * k_aV * moduleaV: ((linearMovementDirection != 0) && (angularMovementDirection < 0))? (4 / 3) * linearMovementDirection * k_V * moduleV: ((linearMovementDirection != 0) && (angularMovementDirection > 0))? (3 / 4) * linearMovementDirection * k_V * moduleV:0;
  39.             var logicConst:int = (((controlbits & FORWARD) && (controlbits & BACK)) && !((controlbits & RIGHT) || (controlbits & LEFT))) || (((controlbits & RIGHT) && (controlbits & LEFT))) && !((controlbits & FORWARD) || (controlbits & BACK))? 0:1;
  40.             var tankState:int = (numContacts == 0)? -1:(numCollision == 0)? 0:1;
  41.             var isFreezed:Boolean = ((moduleV < minSpeed) && (moduleaV < minASpeed))? true:false;
  42.             if((tankState != 0) && ((linearMovementDirection != 0) || (angularMovementDirection != 0)))
  43.             {
  44.                 leftTrackSpeed = (linearMovementDirection != 0) && (angularMovementDirection == 0)? linearMovementDirection * minSpeed: ((linearMovementDirection == 0) && (angularMovementDirection != 0))? -angularMovementDirection * minASpeed * 200000: ((linearMovementDirection != 0) && (angularMovementDirection < 0))? (4 / 3) * linearMovementDirection * minSpeed: ((linearMovementDirection != 0) && (angularMovementDirection > 0))? (3 / 4) * linearMovementDirection * minSpeed:0;
  45.                 leftTrackSpeed*= (tankState == -1)? 15 * k_V * maxSpeed:(isFreezed == true)? k_V * maxSpeed: 15 * k_V * maxSpeed;
  46.             }
  47.             left = leftTrackSpeed;
  48.             Game._leftinput.value = leftTrackSpeed.toString();
  49.            
  50.             return logicConst * leftTrackSpeed;
  51.         }
  52.  
  53.         public static function calculateRightTrackSpeed(moduleV:Number, moduleaV:Number, controlbits:int, numContacts:int, numCollision:int,maxSpeed:Number):Number
  54.         {
  55.             var linearMovementDirection:int = !(controlbits & FORWARD) && !(controlbits & BACK)? 0:!(controlbits & FORWARD) && (controlbits & BACK)? -1:1;
  56.             var angularMovementDirection:int =  !(controlbits & LEFT) && !(controlbits & RIGHT)? 0:!(controlbits & LEFT) && (controlbits & RIGHT)? -1:1;
  57.             var rightTrackSpeed:Number = (linearMovementDirection != 0) && (angularMovementDirection == 0)? linearMovementDirection * k_V * moduleV: ((linearMovementDirection == 0) && (angularMovementDirection != 0))? angularMovementDirection * k_aV * moduleaV: ((linearMovementDirection != 0) && (angularMovementDirection < 0))? (3 / 4) * linearMovementDirection * k_V * moduleV: ((linearMovementDirection != 0) && (angularMovementDirection > 0))? (4 / 3) * linearMovementDirection * k_V * moduleV:0;
  58.             var logicConst:int = (((controlbits & FORWARD) && (controlbits & BACK)) && !((controlbits & RIGHT) || (controlbits & LEFT))) || (((controlbits & RIGHT) && (controlbits & LEFT))) && !((controlbits & FORWARD) || (controlbits & BACK))? 0:1;
  59.             var tankState:int = (numContacts == 0)? -1:(numCollision == 0)? 0:1;
  60.             var isFreezed:Boolean = ((moduleV < minSpeed) && (moduleaV < minASpeed))? true:false;
  61.             if((tankState != 0) && ((linearMovementDirection != 0) || (angularMovementDirection != 0)))
  62.             {
  63.                 rightTrackSpeed = (linearMovementDirection != 0) && (angularMovementDirection == 0)? linearMovementDirection * minSpeed: ((linearMovementDirection == 0) && (angularMovementDirection != 0))? angularMovementDirection * minASpeed * 200000: ((linearMovementDirection != 0) && (angularMovementDirection < 0))? (3 / 4) * linearMovementDirection * minSpeed: ((linearMovementDirection != 0) && (angularMovementDirection > 0))? (4 / 3) * linearMovementDirection * minSpeed:0;
  64.                 rightTrackSpeed *= (tankState == -1)? 15 * k_V * maxSpeed:(isFreezed == true)? k_V * maxSpeed: 15 * k_V * maxSpeed;
  65.             }
  66.             right = logicConst * rightTrackSpeed;
  67.             Game._rigthinput.value = rightTrackSpeed.toString();
  68.    
  69.             return logicConst * rightTrackSpeed;
  70.          
  71.         }
  72.  
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement