Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package alternativa.tanks.vehicles.tanks
- {
- /**
- * ...
- * @author ...
- */
- import alternativa.osgi.service.storage.IStorageService;
- import alternativa.init.Main;
- public class calculateTrackSpeed
- {
- private static const FORWARD:int = 1;
- private static const BACK:int = 2;
- private static const LEFT:int = 4;
- private static const RIGHT:int = 8;
- private static const TURRET_LEFT:int = 16;
- private static const TURRET_RIGHT:int = 32;
- private static const CENTER_TURRET:int = 64;
- private static const REVERSE_TURN_BIT:int = 128;
- private static const minSpeed:Number = 0.1;
- private static const minASpeed:Number = 0.0001;
- private static var k_V:Number = 0.01;
- private static var k_aV:Number = 2;
- private static var left:Number = 0;
- private static var right:Number = 0;
- public function calculateTrackSpeed()
- {
- }
- public static function calculateLeftTrackSpeed(moduleV:Number, moduleaV:Number, controlbits:int, numContacts:int, numCollision:int,maxSpeed:Number):Number
- {
- k_V = IStorageService(Main.osgi.getService(IStorageService)).getStorage().data["k_V"];//isNaN(Number(Game._kV.value))?0.1:Number(Game._kV.value);
- k_aV = IStorageService(Main.osgi.getService(IStorageService)).getStorage().data["k_AV"];//isNaN( Number(Game._kaV.value))?0.1:Number(Game._kaV.value);
- var linearMovementDirection:int = !(controlbits & FORWARD) && !(controlbits & BACK)? 0:!(controlbits & FORWARD) && (controlbits & BACK)? -1:1;
- var angularMovementDirection:int = !(controlbits & LEFT) && !(controlbits & RIGHT)? 0:!(controlbits & LEFT) && (controlbits & RIGHT)? -1:1;
- 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;
- var logicConst:int = (((controlbits & FORWARD) && (controlbits & BACK)) && !((controlbits & RIGHT) || (controlbits & LEFT))) || (((controlbits & RIGHT) && (controlbits & LEFT))) && !((controlbits & FORWARD) || (controlbits & BACK))? 0:1;
- var tankState:int = (numContacts == 0)? -1:(numCollision == 0)? 0:1;
- var isFreezed:Boolean = ((moduleV < minSpeed) && (moduleaV < minASpeed))? true:false;
- if((tankState != 0) && ((linearMovementDirection != 0) || (angularMovementDirection != 0)))
- {
- 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;
- leftTrackSpeed*= (tankState == -1)? 15 * k_V * maxSpeed:(isFreezed == true)? k_V * maxSpeed: 15 * k_V * maxSpeed;
- }
- left = leftTrackSpeed;
- Game._leftinput.value = leftTrackSpeed.toString();
- return logicConst * leftTrackSpeed;
- }
- public static function calculateRightTrackSpeed(moduleV:Number, moduleaV:Number, controlbits:int, numContacts:int, numCollision:int,maxSpeed:Number):Number
- {
- var linearMovementDirection:int = !(controlbits & FORWARD) && !(controlbits & BACK)? 0:!(controlbits & FORWARD) && (controlbits & BACK)? -1:1;
- var angularMovementDirection:int = !(controlbits & LEFT) && !(controlbits & RIGHT)? 0:!(controlbits & LEFT) && (controlbits & RIGHT)? -1:1;
- 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;
- var logicConst:int = (((controlbits & FORWARD) && (controlbits & BACK)) && !((controlbits & RIGHT) || (controlbits & LEFT))) || (((controlbits & RIGHT) && (controlbits & LEFT))) && !((controlbits & FORWARD) || (controlbits & BACK))? 0:1;
- var tankState:int = (numContacts == 0)? -1:(numCollision == 0)? 0:1;
- var isFreezed:Boolean = ((moduleV < minSpeed) && (moduleaV < minASpeed))? true:false;
- if((tankState != 0) && ((linearMovementDirection != 0) || (angularMovementDirection != 0)))
- {
- 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;
- rightTrackSpeed *= (tankState == -1)? 15 * k_V * maxSpeed:(isFreezed == true)? k_V * maxSpeed: 15 * k_V * maxSpeed;
- }
- right = logicConst * rightTrackSpeed;
- Game._rigthinput.value = rightTrackSpeed.toString();
- return logicConst * rightTrackSpeed;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement