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

  1. class Bolt extends BaseObject
  2. {
  3.    var nSpeed;
  4.    var mcRef;
  5.    static var sSTATE_FLYING = "Flying";
  6.    static var sSTATE_EXPLODE = "Explode";
  7.    static var nBOLT_SPEED = 6;
  8.    function Bolt(_mcRef)
  9.    {
  10.       super(_mcRef);
  11.       this.setState(Bolt.sSTATE_FLYING);
  12.       this.nSpeed = Bolt.nBOLT_SPEED;
  13.       var _loc3_ = Library.Sound.SoundManager.isSoundPlaying("Bolt_Shot.mp3");
  14.       if(_loc3_.bPlaying)
  15.       {
  16.          _loc3_.oSound.doStop();
  17.          _loc3_.oSound.doStart();
  18.       }
  19.       Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Bolt_Shot.mp3",75,1,true);
  20.       LevelManager.Instance.doAddListener(this);
  21.    }
  22.    function setPosition(_nPosX, _nPosY)
  23.    {
  24.       this.mcRef._x = _nPosX;
  25.       this.mcRef._y = _nPosY;
  26.    }
  27.    function doDestroy()
  28.    {
  29.       LevelManager.Instance.doRemoveListener(this);
  30.       super.doDestroy();
  31.    }
  32.    function doExplode()
  33.    {
  34.       if(this.isStateComplete())
  35.       {
  36.          this.doDestroy();
  37.       }
  38.    }
  39.    function doFlying()
  40.    {
  41.       var _loc2_ = this.mcRef._y - this.nSpeed;
  42.       _loc2_ = this.doCheckBlocks(_loc2_);
  43.       _loc2_ = this.doCheckTop(_loc2_);
  44.       this.mcRef._y = _loc2_;
  45.    }
  46.    function doCheckBlocks(_nFutureY)
  47.    {
  48.       var _loc3_ = LevelManager.Instance.getNearBlocksForObject(this);
  49.       for(var _loc6_ in _loc3_)
  50.       {
  51.          if(this.getCollideTop(_loc3_[_loc6_],this.Ref._x,_nFutureY))
  52.          {
  53.             _loc3_[_loc6_].onBoltHit();
  54.             var _loc4_ = true;
  55.             if(_loc4_)
  56.             {
  57.                _nFutureY = _loc3_[_loc6_].Bounds.yMax - this.StateBounds.yMin;
  58.             }
  59.             this.setState(Bolt.sSTATE_EXPLODE);
  60.             var _loc2_ = Library.Sound.SoundManager.isSoundPlaying("Bolt_Explode.mp3");
  61.             if(_loc2_.bPlaying)
  62.             {
  63.                _loc2_.oSound.doStop();
  64.                _loc2_.oSound.doStart();
  65.             }
  66.             Library.Sound.SoundManager.doPlaySoundInCat(Main.sSOUND_CAT_SOUND,"Bolt_Explode.mp3",60,1,true);
  67.          }
  68.       }
  69.       return _nFutureY;
  70.    }
  71.    function doCheckTop(_nFutureY)
  72.    {
  73.       if(_nFutureY + this.StateBounds.yMin < LevelManager.nLIMITS_CEIL)
  74.       {
  75.          _nFutureY = LevelManager.nLIMITS_CEIL - this.StateBounds.yMin;
  76.          this.setState(Bolt.sSTATE_EXPLODE);
  77.       }
  78.       return _nFutureY;
  79.    }
  80. }
  81.