home *** CD-ROM | disk | FTP | other *** search
/ One Click 21 (Special) / OC021.iso / Juegos / 05-11-10-1.swf / scripts / __Packages / Vehicule.as < prev   
Encoding:
Text File  |  2005-11-18  |  6.0 KB  |  274 lines

  1. class Vehicule
  2. {
  3.    var SPEED_MAX = 30;
  4.    var SPEED_MIN = -2;
  5.    var SPEED_ACCEL = 1;
  6.    var SPEED_BRAKE = 0.8;
  7.    var SPEED_DECEL = 0.95;
  8.    var SPEED_IDLE = 20;
  9.    var STEERING = 18;
  10.    var STEERING_SPEED = 10;
  11.    var STEERING_MIN_SPEED = 5;
  12.    var STEERING_FACTOR = 3;
  13.    var etat = new String();
  14.    var oldEtat = new String();
  15.    var nom = new String();
  16.    var speed = new Number();
  17.    var changeDir = new String();
  18.    var bounce = new Boolean();
  19.    var mcRef = null;
  20.    var stateLocked = new Boolean();
  21.    var paused = new Boolean();
  22.    function Vehicule(l_mcRef)
  23.    {
  24.       this.nom = l_mcRef._name;
  25.       this.etat = "MoveIdle";
  26.       this.oldEtat = "MoveIdle";
  27.       this.speed = 0;
  28.       this.changeDir = null;
  29.       this.bounce = false;
  30.       this.mcRef = l_mcRef;
  31.       this.stateLocked = false;
  32.       this.paused = false;
  33.    }
  34.    function DoClipHitTest(l_obj, l_mcZone)
  35.    {
  36.       var _loc2_ = new Boolean();
  37.       if(l_mcZone != undefined)
  38.       {
  39.          _loc2_ = this.mcRef[l_mcZone].hitTest(l_obj);
  40.       }
  41.       else
  42.       {
  43.          _loc2_ = this.mcRef.hitTest(l_obj);
  44.       }
  45.       return _loc2_;
  46.    }
  47.    function DoHitTest(l_coord, l_mcZone)
  48.    {
  49.       var _loc2_ = new Boolean();
  50.       if(l_mcZone != undefined)
  51.       {
  52.          _loc2_ = this.mcRef[l_mcZone].hitTest(l_coord.x,l_coord.y,true);
  53.       }
  54.       else
  55.       {
  56.          _loc2_ = this.mcRef.hitTest(l_coord.x,l_coord.y,true);
  57.       }
  58.       return _loc2_;
  59.    }
  60.    function EastOrWeast()
  61.    {
  62.       var _loc2_ = new String();
  63.       if(this.GetPropRotation() >= 0)
  64.       {
  65.          _loc2_ = "e";
  66.       }
  67.       else
  68.       {
  69.          _loc2_ = "w";
  70.       }
  71.       return _loc2_;
  72.    }
  73.    function EnterFrame()
  74.    {
  75.       if(!this.paused)
  76.       {
  77.          this[this.etat]();
  78.       }
  79.    }
  80.    function GetName()
  81.    {
  82.       return this.nom;
  83.    }
  84.    function GetPropCoord()
  85.    {
  86.       var _loc2_ = new Object();
  87.       _loc2_.x = this.mcRef._x;
  88.       _loc2_.y = this.mcRef._y;
  89.       return _loc2_;
  90.    }
  91.    function GetPropRotation()
  92.    {
  93.       return this.mcRef._rotation;
  94.    }
  95.    function GetRotation()
  96.    {
  97.       return this.mcRef._rotation;
  98.    }
  99.    function GetSpeed()
  100.    {
  101.       return this.speed;
  102.    }
  103.    function GetStageCoord()
  104.    {
  105.       var _loc2_ = this.GetPropCoord();
  106.       this.mcRef._parent.localToGlobal(_loc2_);
  107.       return _loc2_;
  108.    }
  109.    function GetState()
  110.    {
  111.       var _loc2_ = new String();
  112.       if(this.stateLocked)
  113.       {
  114.          _loc2_ = "Locked";
  115.       }
  116.       else
  117.       {
  118.          _loc2_ = this.etat;
  119.       }
  120.       return _loc2_;
  121.    }
  122.    function GetTrajectory()
  123.    {
  124.       return this.changeDir;
  125.    }
  126.    function GetZone()
  127.    {
  128.       var _loc3_ = this.GetPropCoord();
  129.       this.mcRef._parent.localToGlobal(_loc3_);
  130.       return _global.C.utils.GetHitZone(_loc3_);
  131.    }
  132.    function Idle()
  133.    {
  134.       if(this.changeDir == "Left")
  135.       {
  136.          this.RotateVeh(- this.STEERING);
  137.       }
  138.       else if(this.changeDir == "Right")
  139.       {
  140.          this.RotateVeh(this.STEERING);
  141.       }
  142.    }
  143.    function IsBouncing()
  144.    {
  145.       return this.bounce;
  146.    }
  147.    function MoveBack()
  148.    {
  149.       var _loc2_ = this.GetSpeed();
  150.       if(_loc2_ > 0)
  151.       {
  152.          _loc2_ *= this.SPEED_BRAKE;
  153.          this.SetSpeed(_loc2_);
  154.          this.MoveVeh();
  155.       }
  156.    }
  157.    function MoveForw()
  158.    {
  159.       if(!this.bounce)
  160.       {
  161.          var _loc2_ = this.GetSpeed();
  162.          _loc2_ += this.SPEED_ACCEL;
  163.          this.SetSpeed(_loc2_);
  164.          this.MoveVeh();
  165.       }
  166.       else
  167.       {
  168.          this.SetSpeed(this.GetSpeed() * this.SPEED_DECEL);
  169.          this.MoveVeh();
  170.       }
  171.    }
  172.    function MoveIdle()
  173.    {
  174.       if(!this.bounce && this.etat != "Inflating")
  175.       {
  176.          if(this.speed > this.SPEED_IDLE)
  177.          {
  178.             this.SetSpeed(this.GetSpeed() * this.SPEED_DECEL);
  179.          }
  180.          else if(this.speed < this.SPEED_IDLE)
  181.          {
  182.             this.SetSpeed(this.GetSpeed() + this.SPEED_ACCEL);
  183.          }
  184.       }
  185.       else
  186.       {
  187.          this.SetSpeed(this.GetSpeed() * this.SPEED_DECEL);
  188.          if(this.GetSpeed() < 1)
  189.          {
  190.             this.SetCommand("Idle");
  191.          }
  192.       }
  193.       this.MoveVeh();
  194.    }
  195.    function MoveVeh()
  196.    {
  197.    }
  198.    function NorthOrSouth()
  199.    {
  200.       var _loc2_ = new String();
  201.       if(Math.abs(this.GetPropRotation()) <= 90)
  202.       {
  203.          _loc2_ = "n";
  204.       }
  205.       else
  206.       {
  207.          _loc2_ = "s";
  208.       }
  209.       return _loc2_;
  210.    }
  211.    function Pause()
  212.    {
  213.       this.mcRef.Etat.stop();
  214.       this.paused = true;
  215.    }
  216.    function RotateVeh(l_steeringValue)
  217.    {
  218.       l_steeringValue /= this.STEERING_FACTOR;
  219.       l_steeringValue += this.GetPropRotation();
  220.       this.SetPropRotation(l_steeringValue);
  221.    }
  222.    function SetCommand(l_state)
  223.    {
  224.       if(!this.stateLocked)
  225.       {
  226.          this.oldEtat = this.etat;
  227.          this.etat = l_state;
  228.       }
  229.    }
  230.    function SetPropRotation(l_rotation)
  231.    {
  232.       this.mcRef._rotation = l_rotation;
  233.    }
  234.    function SetSpeed(l_speed)
  235.    {
  236.       if(l_speed <= this.SPEED_MAX && l_speed >= this.SPEED_MIN)
  237.       {
  238.          this.speed = l_speed;
  239.       }
  240.       if(Math.abs(this.speed) < 1 && Math.abs(this.speed) > 0)
  241.       {
  242.          this.speed = 0;
  243.       }
  244.    }
  245.    function SetState(l_newState)
  246.    {
  247.       if(l_newState != undefined && l_newState != this.etat && !this.stateLocked)
  248.       {
  249.          this.oldEtat = this.etat;
  250.          this.etat = l_newState;
  251.          this.mcRef.gotoAndPlay(l_newState);
  252.       }
  253.    }
  254.    function SetStateLocked()
  255.    {
  256.       this.stateLocked = true;
  257.    }
  258.    function SetTrajectory(l_TurnTo)
  259.    {
  260.       if(!this.stateLocked)
  261.       {
  262.          if(this.changeDir != l_TurnTo && (l_TurnTo == "Left" || l_TurnTo == "Right" || l_TurnTo == null))
  263.          {
  264.             this.changeDir = l_TurnTo;
  265.          }
  266.       }
  267.    }
  268.    function UnPause()
  269.    {
  270.       this.mcRef.Etat.play();
  271.       this.paused = false;
  272.    }
  273. }
  274.