home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / flameout.swf / scripts / __Packages / LRG / LRGMoveAction.as < prev    next >
Encoding:
Text File  |  2006-06-13  |  3.5 KB  |  122 lines

  1. class LRG.LRGMoveAction extends LRG.LRGAction
  2. {
  3.    var m_sActionType;
  4.    var m_fCurrSpeed;
  5.    var m_fGoalRotation;
  6.    var m_kGoal;
  7.    var m_fCosine;
  8.    var m_fSine;
  9.    var m_kObjPos;
  10.    var m_fRotationSpeed;
  11.    function LRGMoveAction(kAnimationParams)
  12.    {
  13.       super();
  14.       this.init(kAnimationParams);
  15.    }
  16.    function init(kActionParams)
  17.    {
  18.       if(kActionParams.m_sType == undefined && (this.m_sActionType == undefined || this.m_sActionType == "DEFAULT"))
  19.       {
  20.          kActionParams.m_sType = "MOVE_ACTION";
  21.       }
  22.       super.init(kActionParams);
  23.       if(kActionParams.m_fSpeed != undefined)
  24.       {
  25.          this.m_fCurrSpeed = kActionParams.m_fSpeed;
  26.       }
  27.       else if(this.m_fCurrSpeed == undefined)
  28.       {
  29.          this.m_fCurrSpeed = 0;
  30.       }
  31.       if(kActionParams.m_fGoalRotation != undefined)
  32.       {
  33.          this.m_fGoalRotation = kActionParams.m_fGoalRotation;
  34.       }
  35.       else if(this.m_fGoalRotation == undefined)
  36.       {
  37.          this.m_fGoalRotation = undefined;
  38.       }
  39.       if(kActionParams.m_kGoal != undefined)
  40.       {
  41.          this.m_kGoal = kActionParams.m_kGoal;
  42.       }
  43.       else if(this.m_kGoal == undefined)
  44.       {
  45.          this.m_kGoal = {x:0,y:0};
  46.       }
  47.    }
  48.    function setCurrSpeed(fSpeed)
  49.    {
  50.       this.m_fCurrSpeed = fSpeed;
  51.    }
  52.    function reset(fCurrTime, kActionParams)
  53.    {
  54.       super.reset(fCurrTime,kActionParams);
  55.       this.m_fCosine = undefined;
  56.       this.m_fSine = undefined;
  57.       this.m_kObjPos = undefined;
  58.    }
  59.    function getTurn(fDegrees, fGoalDegrees)
  60.    {
  61.       var _loc2_ = Math.abs(fGoalDegrees - fDegrees + 360) % 360;
  62.       var _loc1_ = Math.abs(fDegrees - fGoalDegrees + 360) % 360;
  63.       if(_loc2_ < _loc1_)
  64.       {
  65.          return _loc2_;
  66.       }
  67.       return - _loc1_;
  68.    }
  69.    function doUpdate(fCurrTime, fDeltaTimeSecs, kClip)
  70.    {
  71.       if(this.m_kObjPos == undefined)
  72.       {
  73.          this.m_kObjPos = new Object();
  74.          this.m_kObjPos.x = kClip._x;
  75.          this.m_kObjPos.y = kClip._y;
  76.       }
  77.       var _loc3_ = new Object();
  78.       _loc3_.x = this.m_kGoal.x - this.m_kObjPos.x;
  79.       _loc3_.y = this.m_kGoal.y - this.m_kObjPos.y;
  80.       if(this.m_kObjPos.x == this.m_kGoal.x && this.m_kObjPos.y == this.m_kGoal.y)
  81.       {
  82.          if(this.m_fGoalRotation !== undefined)
  83.          {
  84.             kClip._rotation = this.m_fGoalRotation;
  85.          }
  86.          return true;
  87.       }
  88.       if(this.m_fCosine == undefined)
  89.       {
  90.          var _loc5_ = Math.atan2(_loc3_.y,_loc3_.x);
  91.          this.m_fCosine = Math.cos(_loc5_);
  92.          this.m_fSine = Math.sin(_loc5_);
  93.       }
  94.       var _loc4_ = fDeltaTimeSecs * this.m_fCurrSpeed;
  95.       var _loc6_ = Math.sqrt(Math.pow(_loc3_.x,2) + Math.pow(_loc3_.y,2));
  96.       if(this.m_fGoalRotation !== undefined)
  97.       {
  98.          if(this.m_fRotationSpeed === undefined)
  99.          {
  100.             var _loc7_ = _loc6_ / this.m_fCurrSpeed;
  101.             this.m_fRotationSpeed = this.getTurn(kClip._rotation,this.m_fGoalRotation) / _loc7_;
  102.          }
  103.          kClip._rotation += this.m_fRotationSpeed * fDeltaTimeSecs;
  104.       }
  105.       if(_loc4_ >= _loc6_)
  106.       {
  107.          if(this.m_fGoalRotation !== undefined)
  108.          {
  109.             kClip._rotation = this.m_fGoalRotation;
  110.          }
  111.          kClip._x = this.m_kGoal.x;
  112.          kClip._y = this.m_kGoal.y;
  113.          return true;
  114.       }
  115.       this.m_kObjPos.x += _loc4_ * this.m_fCosine;
  116.       this.m_kObjPos.y += _loc4_ * this.m_fSine;
  117.       kClip._x = this.m_kObjPos.x;
  118.       kClip._y = this.m_kObjPos.y;
  119.       return false;
  120.    }
  121. }
  122.