home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Acao / bubble_tanks_2.swf / scripts / __Packages / Enemy_Sapper.as < prev    next >
Encoding:
Text File  |  2008-09-02  |  7.1 KB  |  237 lines

  1. class Enemy_Sapper extends MovieClip
  2. {
  3.    var gunFlagOne;
  4.    var flagExplode;
  5.    var guns;
  6.    var haltMovie;
  7.    var safetyTurn;
  8.    var numLife;
  9.    var numSpeed;
  10.    var numFramesToTurn;
  11.    var numAmountToTurn;
  12.    var minFramesToHoldTurning;
  13.    var strCreatedBy;
  14.    var intState;
  15.    var rotateAngle;
  16.    var rotateSpeed;
  17.    var _type;
  18.    var blnVoid;
  19.    var enemyOff;
  20.    var numLastAngle;
  21.    function Enemy_Sapper()
  22.    {
  23.       super();
  24.       this.gunFlagOne = true;
  25.       this.flagExplode = false;
  26.       this.guns = new Array();
  27.       this.haltMovie = false;
  28.       this.safetyTurn = false;
  29.       this.numLife = 1;
  30.       this.gotoAndPlay(this.numLife);
  31.       this.numSpeed = 6;
  32.       this.numFramesToTurn = 0;
  33.       this.numAmountToTurn = 0;
  34.       this.minFramesToHoldTurning = 0;
  35.       this.strCreatedBy = "";
  36.       this.intState = 3;
  37.       this.rotateAngle = 0;
  38.       this.rotateSpeed = 0.1;
  39.       this._type = 2;
  40.       this.blnVoid = false;
  41.    }
  42.    function onEnterFrame()
  43.    {
  44.       if(!this.enemyOff)
  45.       {
  46.          if(this.intState == 3 || this.intState == 5)
  47.          {
  48.             if(this.haltMovie == false)
  49.             {
  50.                this.numLastAngle = this.GetAnglePos();
  51.                this.MoveMe();
  52.                var _loc10_ = this.AboutToExit();
  53.             }
  54.             if(this.intState == 3)
  55.             {
  56.                if(this.minFramesToHoldTurning > 0)
  57.                {
  58.                   this.minFramesToHoldTurning = this.minFramesToHoldTurning - 1;
  59.                }
  60.                else
  61.                {
  62.                   var _loc3_ = new Vector();
  63.                   _loc3_._x = _root.avatar._x - this._x;
  64.                   _loc3_._y = _root.avatar._y - this._y;
  65.                   var _loc6_ = Math.atan2(_loc3_._y,_loc3_._x);
  66.                   var _loc7_ = 360 * _loc6_ / 6.283185307179586;
  67.                   this._rotation = _loc7_;
  68.                }
  69.                if(_root.game.intAssembledState == 0)
  70.                {
  71.                   if(this.GetDistance2Avatar() <= 20)
  72.                   {
  73.                      this.gotoAndStop(11);
  74.                      var _loc4_ = new Vector();
  75.                      _loc4_._x = _root.avatar._x;
  76.                      _loc4_._y = _root.avatar._y;
  77.                      _root.game.CreateEffect("effect",_loc4_,true,"avatar");
  78.                      _root.ReportAvatarDamage(1);
  79.                      this.intState = 5;
  80.                   }
  81.                }
  82.             }
  83.             else if(this.intState == 5)
  84.             {
  85.                if(this.minFramesToHoldTurning > 0)
  86.                {
  87.                   this.minFramesToHoldTurning = this.minFramesToHoldTurning - 1;
  88.                }
  89.                else
  90.                {
  91.                   _loc3_ = new Vector();
  92.                   _loc3_._x = _root[this.strCreatedBy]._x - this._x;
  93.                   _loc3_._y = _root[this.strCreatedBy]._y - this._y;
  94.                   _loc6_ = Math.atan2(_loc3_._y,_loc3_._x);
  95.                   _loc7_ = 360 * _loc6_ / 6.283185307179586;
  96.                   this._rotation = _loc7_;
  97.                }
  98.                if(this.GetDistance2Source() <= 20)
  99.                {
  100.                   this.intState = 3;
  101.                   _root[this.strCreatedBy].ReportLifeIncrease(3);
  102.                   this.gotoAndStop(1);
  103.                }
  104.             }
  105.          }
  106.          else if(this.intState == 2)
  107.          {
  108.             var _loc5_ = _root[this.strCreatedBy]._width + 2;
  109.             var _loc9_ = _loc5_ * Math.cos(this.rotateAngle) + _root[this.strCreatedBy]._x;
  110.             var _loc8_ = _loc5_ * Math.sin(this.rotateAngle) + _root[this.strCreatedBy]._y;
  111.             this.rotateAngle += this.rotateSpeed;
  112.             if(this.rotateAngle > 360)
  113.             {
  114.                this.rotateAngle = 0;
  115.             }
  116.             this._x = _loc9_;
  117.             this._y = _loc8_;
  118.             this._rotation = _root[this.strCreatedBy]._rotation;
  119.             if(this.GetDistance2Avatar() <= 85)
  120.             {
  121.                this.intState = 3;
  122.             }
  123.          }
  124.       }
  125.    }
  126.    function Explode()
  127.    {
  128.       this.gotoAndPlay(2);
  129.       this.intState = 4;
  130.    }
  131.    function Terminate()
  132.    {
  133.       this.blnVoid = true;
  134.       this.Explode();
  135.    }
  136.    function KillMe()
  137.    {
  138.       if(this.blnVoid == false)
  139.       {
  140.          _root.ReportAvatarDamage(8);
  141.       }
  142.       _root.ReportDeath(this._name);
  143.       _root[this.strCreatedBy].ReportSeekerDeath(this._name);
  144.       this.removeMovieClip();
  145.    }
  146.    function SetCreatedFrom(strFrom)
  147.    {
  148.       this.strCreatedBy = strFrom;
  149.    }
  150.    function ReceiveDamage(amountDamage)
  151.    {
  152.       var _loc3_ = false;
  153.       this.numLife -= amountDamage;
  154.       if(this.numLife < 1)
  155.       {
  156.          _loc3_ = true;
  157.          _root.ReportDeath(this._name);
  158.          _root[this.strCreatedBy].ReportSeekerDeath(this._name);
  159.          this.removeMovieClip();
  160.       }
  161.       else
  162.       {
  163.          this.gotoAndStop(this.numLife);
  164.       }
  165.       return _loc3_;
  166.    }
  167.    function RemoveGun(strName)
  168.    {
  169.       var _loc2_ = 0;
  170.       while(_loc2_ < this.guns.length)
  171.       {
  172.          if(strName == this.guns[_loc2_].name)
  173.          {
  174.             this.guns.splice(_loc2_,1);
  175.             break;
  176.          }
  177.          _loc2_ = _loc2_ + 1;
  178.       }
  179.    }
  180.    function MoveMe()
  181.    {
  182.       var _loc2_ = new Vector();
  183.       _loc2_._x = Math.cos(3.141592653589793 * this._rotation / 180) * this.numSpeed + this._x;
  184.       _loc2_._y = Math.sin(3.141592653589793 * this._rotation / 180) * this.numSpeed + this._y;
  185.       this._x = _loc2_._x;
  186.       this._y = _loc2_._y;
  187.    }
  188.    function GetAnglePos()
  189.    {
  190.       var _loc3_ = new Vector();
  191.       _loc3_._x = this._x - _root.bg._x;
  192.       _loc3_._y = this._y - _root.bg._y;
  193.       var _loc4_ = Math.atan2(_loc3_._y,_loc3_._x);
  194.       var _loc5_ = 360 * _loc4_ / 6.283185307179586;
  195.       return _loc5_;
  196.    }
  197.    function GetDistance()
  198.    {
  199.       var _loc4_ = this._x - _root.bg._x;
  200.       var _loc3_ = this._y - _root.bg._y;
  201.       return Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_);
  202.    }
  203.    function GetDistance2Avatar()
  204.    {
  205.       var _loc4_ = this._x - _root.avatar._x;
  206.       var _loc3_ = this._y - _root.avatar._y;
  207.       return Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_);
  208.    }
  209.    function GetDistance2Source()
  210.    {
  211.       var _loc4_ = this._x - _root[this.strCreatedBy]._x;
  212.       var _loc3_ = this._y - _root[this.strCreatedBy]._y;
  213.       return Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_);
  214.    }
  215.    function AboutToExit()
  216.    {
  217.       var _loc5_ = false;
  218.       var _loc6_ = Math.cos(3.141592653589793 * this._rotation / 180) * (this._width + 30 * this.numSpeed) + this._x;
  219.       var _loc7_ = Math.sin(3.141592653589793 * this._rotation / 180) * (this._width + 30 * this.numSpeed) + this._y;
  220.       var _loc4_ = _loc6_ - _root.bg._x;
  221.       var _loc3_ = _loc7_ - _root.bg._y;
  222.       if(Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_) > _root.bg.inside._width / 2)
  223.       {
  224.          _loc5_ = true;
  225.       }
  226.       return _loc5_;
  227.    }
  228.    function TurnOff()
  229.    {
  230.       this.enemyOff = true;
  231.    }
  232.    function TurnOn()
  233.    {
  234.       this.enemyOff = false;
  235.    }
  236. }
  237.