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

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