home *** CD-ROM | disk | FTP | other *** search
/ Champak 48 / cdrom_image.iso / Games / breakawish.swf / scripts / __Packages / BaseObject.as < prev    next >
Encoding:
Text File  |  2007-09-28  |  7.9 KB  |  272 lines

  1. class BaseObject extends Library.State
  2. {
  3.    var nOriginalScaleX;
  4.    var mcRef;
  5.    var nOriginalScaleY;
  6.    var bDropDownMotion;
  7.    var bLevelEnded;
  8.    var nOriginalPositionX;
  9.    var nOriginalPositionY;
  10.    var oTweenListener;
  11.    var twX;
  12.    var twY;
  13.    var oStateBounds;
  14.    var bPaused;
  15.    static var nDROP_DOWN_HEIGHT = 400;
  16.    static var nDROP_DISTANCE_MOVE_PERCENT = 0.35;
  17.    static var nDROP_MAX_SPEED = 40;
  18.    static var nDROP_MIN_MOVE = 4;
  19.    static var nBOUNCE_DURATION = 15;
  20.    static var nBOUNCE_VERTICAL_STRETCH = 65;
  21.    static var nBOUNCE_HORIZONTAL_STRETCH = 60;
  22.    static var nBOUNCE_VERTICAL_SPEED_RATIO = 2;
  23.    static var nBOUNCE_HORIZONTAL_SPEED_RATIO = 2;
  24.    function BaseObject(_mcRef)
  25.    {
  26.       super(_mcRef);
  27.       this.nOriginalScaleX = this.mcRef._xscale;
  28.       this.nOriginalScaleY = this.mcRef._yscale;
  29.       this.bDropDownMotion = false;
  30.       this.bLevelEnded = false;
  31.       this.nOriginalPositionX = this.mcRef._x;
  32.       this.nOriginalPositionY = this.mcRef._y;
  33.       this.oTweenListener = new Object();
  34.       this.oTweenListener.onMotionFinished = Library.Utils.Delegate.create(this,this.onTweenComplete);
  35.    }
  36.    function doEnterFrame()
  37.    {
  38.       super.doEnterFrame();
  39.       if(this.bDropDownMotion)
  40.       {
  41.          var _loc4_ = this.nOriginalPositionY - this.mcRef._y;
  42.          var _loc3_ = undefined;
  43.          if(_loc4_ > BaseObject.nDROP_MIN_MOVE)
  44.          {
  45.             _loc3_ = _loc4_ * BaseObject.nDROP_DISTANCE_MOVE_PERCENT;
  46.          }
  47.          else
  48.          {
  49.             _loc3_ = _loc4_;
  50.             LevelManager.Instance.onDropDownCompleteForElement(this);
  51.             this.bDropDownMotion = false;
  52.          }
  53.          if(_loc3_ > BaseObject.nDROP_MAX_SPEED)
  54.          {
  55.             _loc3_ = BaseObject.nDROP_MAX_SPEED;
  56.          }
  57.          this.mcRef._y += _loc3_;
  58.       }
  59.    }
  60.    function onLevelEnded()
  61.    {
  62.       this.bLevelEnded = true;
  63.    }
  64.    function doLevelEndedAnim()
  65.    {
  66.       this.setState("Explode");
  67.    }
  68.    function onHideForDropDown()
  69.    {
  70.       this.mcRef._y = this.nOriginalPositionY - BaseObject.nDROP_DOWN_HEIGHT;
  71.    }
  72.    function onStartDropDownMove()
  73.    {
  74.       this.bDropDownMotion = true;
  75.    }
  76.    function doPause()
  77.    {
  78.       super.doPause();
  79.       this.twX.stop();
  80.       this.twY.stop();
  81.    }
  82.    function doResume()
  83.    {
  84.       super.doResume();
  85.       this.twX.resume();
  86.       this.twY.resume();
  87.    }
  88.    function onTweenComplete(__twTween)
  89.    {
  90.       if(__twTween == this.twX)
  91.       {
  92.          delete this.twX;
  93.       }
  94.       else if(__twTween == this.twY)
  95.       {
  96.          delete this.twY;
  97.       }
  98.    }
  99.    function doDestroy()
  100.    {
  101.       this.mcRef.swapDepths(LevelManager.Instance.RemoveDepth);
  102.       this.mcRef.removeMovieClip();
  103.       if(this.bLevelEnded)
  104.       {
  105.          LevelManager.Instance.onLevelEndAnimEnded(this);
  106.       }
  107.       this.twX.stop();
  108.       this.twY.stop();
  109.       delete this.twX;
  110.       delete this.twY;
  111.       delete this.mcRef;
  112.       delete this.oStateBounds;
  113.    }
  114.    function get Ref()
  115.    {
  116.       return this.mcRef;
  117.    }
  118.    function get StateBounds()
  119.    {
  120.       return this.oStateBounds;
  121.    }
  122.    function get Bounds()
  123.    {
  124.       var _loc2_ = new Object();
  125.       _loc2_.xMin = this.mcRef._x + this.oStateBounds.xMin;
  126.       _loc2_.xMax = this.mcRef._x + this.oStateBounds.xMax;
  127.       _loc2_.yMin = this.mcRef._y + this.oStateBounds.yMin;
  128.       _loc2_.yMax = this.mcRef._y + this.oStateBounds.yMax;
  129.       return _loc2_;
  130.    }
  131.    function doExplode()
  132.    {
  133.       if(this.isStateComplete())
  134.       {
  135.          this.doDestroy();
  136.       }
  137.    }
  138.    function doBounce(__nXStrength, __nYStrength)
  139.    {
  140.       if(!this.bPaused)
  141.       {
  142.          var _loc2_ = 100 - Math.abs(__nXStrength) * BaseObject.nBOUNCE_HORIZONTAL_SPEED_RATIO;
  143.          var _loc3_ = 100 - Math.abs(__nYStrength) * BaseObject.nBOUNCE_VERTICAL_SPEED_RATIO;
  144.          if(_loc2_ < BaseObject.nBOUNCE_HORIZONTAL_STRETCH || _loc2_ > 100)
  145.          {
  146.             _loc2_ = BaseObject.nBOUNCE_HORIZONTAL_STRETCH;
  147.          }
  148.          if(_loc3_ < BaseObject.nBOUNCE_VERTICAL_STRETCH || _loc3_ > 100)
  149.          {
  150.             _loc3_ = BaseObject.nBOUNCE_VERTICAL_STRETCH;
  151.          }
  152.          this.doReinitScale();
  153.          if(this.twX != undefined)
  154.          {
  155.             this.twX.stop();
  156.          }
  157.          if(this.twY != undefined)
  158.          {
  159.             this.twY.stop();
  160.          }
  161.          this.twX = new mx.transitions.Tween(this.mcRef,"_xscale",mx.transitions.easing.Elastic.easeOut,_loc2_,this.mcRef._xscale,BaseObject.nBOUNCE_DURATION,false);
  162.          this.twY = new mx.transitions.Tween(this.mcRef,"_yscale",mx.transitions.easing.Elastic.easeOut,_loc3_,this.mcRef._yscale,BaseObject.nBOUNCE_DURATION,false);
  163.          this.twX.addListener(this.oTweenListener);
  164.          this.twY.addListener(this.oTweenListener);
  165.       }
  166.    }
  167.    function doReinitScale()
  168.    {
  169.       this.mcRef._xscale = this.nOriginalScaleX;
  170.       this.mcRef._yscale = this.nOriginalScaleY;
  171.    }
  172.    function getCollideBottom(_oTargetObject, _nX, _nY)
  173.    {
  174.       if(_nX == undefined)
  175.       {
  176.          _nX = this.Ref._x;
  177.       }
  178.       if(_nY == undefined)
  179.       {
  180.          _nY = this.Ref._y;
  181.       }
  182.       var _loc2_ = false;
  183.       if(_nX > _oTargetObject.Bounds.xMin && _nX < _oTargetObject.Bounds.xMax)
  184.       {
  185.          var _loc7_ = Library.Utils.MoreMath.getBoundsCenter(_oTargetObject.Bounds).y;
  186.          var _loc5_ = Library.Utils.MoreMath.getBoundsCenter(this.Bounds).y;
  187.          if(_nY + this.StateBounds.yMax > _oTargetObject.Bounds.yMin && _loc5_ < _loc7_)
  188.          {
  189.             _loc2_ = true;
  190.          }
  191.       }
  192.       return _loc2_;
  193.    }
  194.    function getCollideTop(_oTargetObject, _nX, _nY)
  195.    {
  196.       if(_nX == undefined)
  197.       {
  198.          _nX = this.Ref._x;
  199.       }
  200.       if(_nY == undefined)
  201.       {
  202.          _nY = this.Ref._y;
  203.       }
  204.       var _loc2_ = false;
  205.       if(_nX > _oTargetObject.Bounds.xMin && _nX < _oTargetObject.Bounds.xMax)
  206.       {
  207.          var _loc7_ = Library.Utils.MoreMath.getBoundsCenter(_oTargetObject.Bounds).y;
  208.          var _loc5_ = Library.Utils.MoreMath.getBoundsCenter(this.Bounds).y;
  209.          if(_nY + this.StateBounds.yMin < _oTargetObject.Bounds.yMax && _loc5_ > _loc7_)
  210.          {
  211.             _loc2_ = true;
  212.          }
  213.       }
  214.       return _loc2_;
  215.    }
  216.    function getCollideRight(_oTargetObject, _nX, _nY)
  217.    {
  218.       if(_nX == undefined)
  219.       {
  220.          _nX = this.Ref._x;
  221.       }
  222.       if(_nY == undefined)
  223.       {
  224.          _nY = this.Ref._y;
  225.       }
  226.       var _loc2_ = false;
  227.       if(_nY > _oTargetObject.Bounds.yMin && _nY < _oTargetObject.Bounds.yMax)
  228.       {
  229.          var _loc7_ = Library.Utils.MoreMath.getBoundsCenter(_oTargetObject.Bounds).x;
  230.          var _loc5_ = Library.Utils.MoreMath.getBoundsCenter(this.Bounds).x;
  231.          if(_nX + this.StateBounds.xMax > _oTargetObject.Bounds.xMin && _loc5_ < _loc7_)
  232.          {
  233.             _loc2_ = true;
  234.          }
  235.       }
  236.       return _loc2_;
  237.    }
  238.    function getCollideLeft(_oTargetObject, _nX, _nY)
  239.    {
  240.       if(_nX == undefined)
  241.       {
  242.          _nX = this.Ref._x;
  243.       }
  244.       if(_nY == undefined)
  245.       {
  246.          _nY = this.Ref._y;
  247.       }
  248.       var _loc2_ = false;
  249.       if(_nY > _oTargetObject.Bounds.yMin && _nY < _oTargetObject.Bounds.yMax)
  250.       {
  251.          var _loc7_ = Library.Utils.MoreMath.getBoundsCenter(_oTargetObject.Bounds).x;
  252.          var _loc5_ = Library.Utils.MoreMath.getBoundsCenter(this.Bounds).x;
  253.          if(_nX + this.StateBounds.xMin < _oTargetObject.Bounds.xMax && _loc5_ > _loc7_)
  254.          {
  255.             _loc2_ = true;
  256.          }
  257.       }
  258.       return _loc2_;
  259.    }
  260.    function doLoadStateAction()
  261.    {
  262.       if(this.mcRef.mcState.mcHit != undefined)
  263.       {
  264.          this.oStateBounds = this.mcRef.mcState.mcHit.getBounds(this.mcRef);
  265.       }
  266.       else
  267.       {
  268.          this.oStateBounds = this.mcRef.mcState.getBounds(this.mcRef);
  269.       }
  270.    }
  271. }
  272.