home *** CD-ROM | disk | FTP | other *** search
- class LRG.LRGMoveAction extends LRG.LRGAction
- {
- var m_sActionType;
- var m_fCurrSpeed;
- var m_fGoalRotation;
- var m_kGoal;
- var m_fCosine;
- var m_fSine;
- var m_kObjPos;
- var m_fRotationSpeed;
- function LRGMoveAction(kAnimationParams)
- {
- super();
- this.init(kAnimationParams);
- }
- function init(kActionParams)
- {
- if(kActionParams.m_sType == undefined && (this.m_sActionType == undefined || this.m_sActionType == "DEFAULT"))
- {
- kActionParams.m_sType = "MOVE_ACTION";
- }
- super.init(kActionParams);
- if(kActionParams.m_fSpeed != undefined)
- {
- this.m_fCurrSpeed = kActionParams.m_fSpeed;
- }
- else if(this.m_fCurrSpeed == undefined)
- {
- this.m_fCurrSpeed = 0;
- }
- if(kActionParams.m_fGoalRotation != undefined)
- {
- this.m_fGoalRotation = kActionParams.m_fGoalRotation;
- }
- else if(this.m_fGoalRotation == undefined)
- {
- this.m_fGoalRotation = undefined;
- }
- if(kActionParams.m_kGoal != undefined)
- {
- this.m_kGoal = kActionParams.m_kGoal;
- }
- else if(this.m_kGoal == undefined)
- {
- this.m_kGoal = {x:0,y:0};
- }
- }
- function setCurrSpeed(fSpeed)
- {
- this.m_fCurrSpeed = fSpeed;
- }
- function reset(fCurrTime, kActionParams)
- {
- super.reset(fCurrTime,kActionParams);
- this.m_fCosine = undefined;
- this.m_fSine = undefined;
- this.m_kObjPos = undefined;
- }
- function getTurn(fDegrees, fGoalDegrees)
- {
- var _loc2_ = Math.abs(fGoalDegrees - fDegrees + 360) % 360;
- var _loc1_ = Math.abs(fDegrees - fGoalDegrees + 360) % 360;
- if(_loc2_ < _loc1_)
- {
- return _loc2_;
- }
- return - _loc1_;
- }
- function doUpdate(fCurrTime, fDeltaTimeSecs, kClip)
- {
- if(this.m_kObjPos == undefined)
- {
- this.m_kObjPos = new Object();
- this.m_kObjPos.x = kClip._x;
- this.m_kObjPos.y = kClip._y;
- }
- var _loc3_ = new Object();
- _loc3_.x = this.m_kGoal.x - this.m_kObjPos.x;
- _loc3_.y = this.m_kGoal.y - this.m_kObjPos.y;
- if(this.m_kObjPos.x == this.m_kGoal.x && this.m_kObjPos.y == this.m_kGoal.y)
- {
- if(this.m_fGoalRotation !== undefined)
- {
- kClip._rotation = this.m_fGoalRotation;
- }
- return true;
- }
- if(this.m_fCosine == undefined)
- {
- var _loc5_ = Math.atan2(_loc3_.y,_loc3_.x);
- this.m_fCosine = Math.cos(_loc5_);
- this.m_fSine = Math.sin(_loc5_);
- }
- var _loc4_ = fDeltaTimeSecs * this.m_fCurrSpeed;
- var _loc6_ = Math.sqrt(Math.pow(_loc3_.x,2) + Math.pow(_loc3_.y,2));
- if(this.m_fGoalRotation !== undefined)
- {
- if(this.m_fRotationSpeed === undefined)
- {
- var _loc7_ = _loc6_ / this.m_fCurrSpeed;
- this.m_fRotationSpeed = this.getTurn(kClip._rotation,this.m_fGoalRotation) / _loc7_;
- }
- kClip._rotation += this.m_fRotationSpeed * fDeltaTimeSecs;
- }
- if(_loc4_ >= _loc6_)
- {
- if(this.m_fGoalRotation !== undefined)
- {
- kClip._rotation = this.m_fGoalRotation;
- }
- kClip._x = this.m_kGoal.x;
- kClip._y = this.m_kGoal.y;
- return true;
- }
- this.m_kObjPos.x += _loc4_ * this.m_fCosine;
- this.m_kObjPos.y += _loc4_ * this.m_fSine;
- kClip._x = this.m_kObjPos.x;
- kClip._y = this.m_kObjPos.y;
- return false;
- }
- }
-