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

  1. class Ally_Fighter extends MovieClip
  2. {
  3.    var gunFlagOne;
  4.    var flagExplode;
  5.    var guns;
  6.    var haltMovie;
  7.    var safetyTurn;
  8.    var numLife;
  9.    var strMiniBubbleName;
  10.    var numSpeed;
  11.    var numFramesToTurn;
  12.    var numAmountToTurn;
  13.    var minFramesToHoldTurning;
  14.    var enemyOff;
  15.    var _damage;
  16.    var _strCreatedBy;
  17.    var _currentTarget;
  18.    var intLastCheckTarget;
  19.    var intFocus;
  20.    var vecFocusOffset;
  21.    var intShootingRange;
  22.    var intResetOffsetCounter;
  23.    var intState;
  24.    var _type;
  25.    function Ally_Fighter()
  26.    {
  27.       super();
  28.       this.gunFlagOne = true;
  29.       this.flagExplode = false;
  30.       this.guns = new Array();
  31.       this.haltMovie = false;
  32.       this.safetyTurn = false;
  33.       this.numLife = 1;
  34.       this.gotoAndPlay(this.numLife);
  35.       this.strMiniBubbleName = "";
  36.       this.numSpeed = 8;
  37.       this.numFramesToTurn = 0;
  38.       this.numAmountToTurn = 0;
  39.       this.minFramesToHoldTurning = 0;
  40.       this.enemyOff = false;
  41.       this._damage = 0;
  42.       this._strCreatedBy = "";
  43.       this._currentTarget = "";
  44.       this.intLastCheckTarget = 0;
  45.       this.intFocus = 2;
  46.       this.vecFocusOffset = new Vector();
  47.       this.intShootingRange = 100;
  48.       this.intResetOffsetCounter = 45;
  49.       this.intState = 3;
  50.       this._type = 10;
  51.       this.guns.push({name:"gun_1",type:1,fireTimerMax:8,fireTimerMin:8,counter:8,speed:10,size:75,damage:1});
  52.    }
  53.    function onEnterFrame()
  54.    {
  55.       if(!this.enemyOff)
  56.       {
  57.          if(this.intState != 2)
  58.          {
  59.             if(this.intState == 3)
  60.             {
  61.                var _loc3_ = this.GetVector2Focus();
  62.                if(_loc3_.GetLength() > this.intShootingRange)
  63.                {
  64.                   this._rotation += _loc3_.AngleToAlign(this._rotation,this.numSpeed,2);
  65.                }
  66.                else
  67.                {
  68.                   if(this.intLastCheckTarget == 0)
  69.                   {
  70.                      this._currentTarget = _root.game.GetNearestEnemy(this._x,this._y);
  71.                      this.intLastCheckTarget = 20;
  72.                   }
  73.                   else
  74.                   {
  75.                      this.intLastCheckTarget = this.intLastCheckTarget - 1;
  76.                   }
  77.                   if(this._currentTarget == "")
  78.                   {
  79.                      this.intState = 4;
  80.                   }
  81.                   if(_root[this._currentTarget]._name == undefined)
  82.                   {
  83.                      this._currentTarget = _root.game.GetNearestEnemy(this._x,this._y);
  84.                      this.intLastCheckTarget = 20;
  85.                      if(_root[this._currentTarget]._name == undefined)
  86.                      {
  87.                         this.intState = 4;
  88.                      }
  89.                   }
  90.                   if(this.intState == 3)
  91.                   {
  92.                      this.OperateWeapons();
  93.                   }
  94.                }
  95.             }
  96.             else if(this.intState == 4)
  97.             {
  98.                _loc3_ = this.GetVector2Focus();
  99.                this._rotation += _loc3_.AngleToAlign(this._rotation,this.numSpeed,2);
  100.                if(_loc3_.GetLength() < this.numSpeed)
  101.                {
  102.                   this.Dock();
  103.                }
  104.             }
  105.          }
  106.          this.MoveMe();
  107.          if(this.intResetOffsetCounter == 0)
  108.          {
  109.             this.ResetOffset();
  110.             this.intResetOffsetCounter = 45;
  111.          }
  112.          else
  113.          {
  114.             this.intResetOffsetCounter = this.intResetOffsetCounter - 1;
  115.          }
  116.       }
  117.    }
  118.    function RandNum(minVal, maxVal)
  119.    {
  120.       return Math.round(Math.random() * (maxVal - minVal)) + minVal;
  121.    }
  122.    function SelfDestruct()
  123.    {
  124.    }
  125.    function Dock()
  126.    {
  127.       this.RemoveMiniBubble();
  128.       _root.game.RemoveAlly(this._name);
  129.       this.removeMovieClip();
  130.    }
  131.    function CreateMiniBubble()
  132.    {
  133.       if(this.strMiniBubbleName == "")
  134.       {
  135.          this.strMiniBubbleName = this._name + "_miniBubble";
  136.          _root.miniBubblesLayer_mc.attachMovie("fighter_bubble",this.strMiniBubbleName,this.getDepth());
  137.          var refBubble = eval("_root.miniBubblesLayer_mc." + this.strMiniBubbleName);
  138.          var point = {x:this._x,y:this._y};
  139.          refBubble._parent.globalToLocal(point);
  140.          refBubble._x = point.x;
  141.          refBubble._y = point.y;
  142.       }
  143.    }
  144.    function RemoveMiniBubble()
  145.    {
  146.       if(this.strMiniBubbleName != "")
  147.       {
  148.          var refBubble = eval("_root.miniBubblesLayer_mc." + this.strMiniBubbleName);
  149.          refBubble.removeMovieClip();
  150.          this.strMiniBubbleName = "";
  151.       }
  152.    }
  153.    function MoveMiniBubble()
  154.    {
  155.       if(this.InRange() == true)
  156.       {
  157.          if(this.strMiniBubbleName == "")
  158.          {
  159.             this.CreateMiniBubble();
  160.          }
  161.       }
  162.       else if(this.strMiniBubbleName != "")
  163.       {
  164.          this.RemoveMiniBubble();
  165.       }
  166.       if(this.strMiniBubbleName != "")
  167.       {
  168.          var refBubble = eval("_root.miniBubblesLayer_mc." + this.strMiniBubbleName);
  169.          var point = {x:this._x,y:this._y};
  170.          refBubble._parent.globalToLocal(point);
  171.          refBubble._x = point.x;
  172.          refBubble._y = point.y;
  173.       }
  174.    }
  175.    function OperateWeapons()
  176.    {
  177.       var i = 0;
  178.       while(i < this.guns.length)
  179.       {
  180.          if(this.guns[i].type == 1)
  181.          {
  182.             var ObjRef = eval("this." + this.guns[i].name);
  183.             var point = {x:ObjRef._x,y:ObjRef._y};
  184.             ObjRef.localToGlobal(point);
  185.             var refTarget = _root[this._currentTarget];
  186.             var vecDirection = new Vector();
  187.             vecDirection._x = refTarget._x - point.x;
  188.             vecDirection._y = refTarget._y - point.y;
  189.             if(vecDirection.GetLength() < this.intShootingRange)
  190.             {
  191.                var myRadians = Math.atan2(vecDirection._y,vecDirection._x);
  192.                var myDegrees = 360 * myRadians / 6.283185307179586;
  193.                ObjRef._rotation = myDegrees - this._rotation;
  194.                if(this.guns[i].counter < 1)
  195.                {
  196.                   var posVector = new Vector();
  197.                   var ObjRefTwo = eval("this." + this.guns[i].name + ".emitter");
  198.                   var pointTwo = {x:ObjRefTwo._x,y:ObjRefTwo._y};
  199.                   ObjRefTwo.localToGlobal(pointTwo);
  200.                   posVector._x = pointTwo.x;
  201.                   posVector._y = pointTwo.y;
  202.                   _root.game.AvatarFireBullet(posVector,ObjRef._rotation + this._rotation,this.guns[i].speed,this.guns[i].size,this.guns[i].damage);
  203.                   this.guns[i].counter = Math.round(Math.random() * (this.guns[i].fireTimerMax - this.guns[i].fireTimerMin)) + this.guns[i].fireTimerMin;
  204.                }
  205.                else
  206.                {
  207.                   this.guns[i].counter--;
  208.                }
  209.             }
  210.          }
  211.          i++;
  212.       }
  213.    }
  214.    function ReceiveDamage(amountDamage)
  215.    {
  216.       var _loc3_ = false;
  217.       this.numLife -= amountDamage;
  218.       if(this.numLife < 1)
  219.       {
  220.          _loc3_ = true;
  221.          _root.ReportDeath(this._name);
  222.          this.removeMovieClip();
  223.       }
  224.       else
  225.       {
  226.          this.gotoAndStop(this.numLife);
  227.       }
  228.       return _loc3_;
  229.    }
  230.    function RemoveGun(strName)
  231.    {
  232.       var _loc2_ = 0;
  233.       while(_loc2_ < this.guns.length)
  234.       {
  235.          if(strName == this.guns[_loc2_].name)
  236.          {
  237.             this.guns.splice(_loc2_,1);
  238.             break;
  239.          }
  240.          _loc2_ = _loc2_ + 1;
  241.       }
  242.    }
  243.    function MoveMe()
  244.    {
  245.       var _loc2_ = new Vector();
  246.       _loc2_._x = Math.cos(3.141592653589793 * this._rotation / 180) * this.numSpeed + this._x;
  247.       _loc2_._y = Math.sin(3.141592653589793 * this._rotation / 180) * this.numSpeed + this._y;
  248.       this._x = _loc2_._x;
  249.       this._y = _loc2_._y;
  250.       this.MoveMiniBubble();
  251.    }
  252.    function GetAnglePos()
  253.    {
  254.       var _loc3_ = new Vector();
  255.       _loc3_._x = this._x - _root.bg._x;
  256.       _loc3_._y = this._y - _root.bg._y;
  257.       var _loc4_ = Math.atan2(_loc3_._y,_loc3_._x);
  258.       var _loc5_ = 360 * _loc4_ / 6.283185307179586;
  259.       return _loc5_;
  260.    }
  261.    function InRange()
  262.    {
  263.       return this.GetDistance() > _root.bg.inside._width / 2 - 30;
  264.    }
  265.    function GetDistance()
  266.    {
  267.       var _loc4_ = this._x - _root.bg._x;
  268.       var _loc3_ = this._y - _root.bg._y;
  269.       return Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_);
  270.    }
  271.    function GetDistance2Target()
  272.    {
  273.       var _loc4_ = this._x - _root[this._currentTarget]._x;
  274.       var _loc3_ = this._y - _root[this._currentTarget]._y;
  275.       return Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_);
  276.    }
  277.    function GetVector2Focus()
  278.    {
  279.       var vecReturn = new Vector();
  280.       if(this.intState == 4)
  281.       {
  282.          var gunRef = eval("_root.avatar.gun." + this._strCreatedBy);
  283.          if(gunRef._name == undefined)
  284.          {
  285.             _root.game.Effect_PierceExplosion(this._x,this._y);
  286.             this.Dock();
  287.          }
  288.          else
  289.          {
  290.             var point = {x:gunRef.emitter._x,y:gunRef.emitter._y};
  291.             gunRef.localToGlobal(point);
  292.             vecReturn._x = point.x - this._x;
  293.             vecReturn._y = point.y - this._y;
  294.          }
  295.       }
  296.       else if(this.intFocus != 1)
  297.       {
  298.          vecReturn._x = _root._xmouse + this.vecFocusOffset._x - this._x;
  299.          vecReturn._y = _root._ymouse + this.vecFocusOffset._y - this._y;
  300.       }
  301.       return vecReturn;
  302.    }
  303.    function ResetOffset()
  304.    {
  305.       this.vecFocusOffset._x = this.RandNum(-25,25);
  306.       this.vecFocusOffset._y = this.RandNum(-25,25);
  307.    }
  308.    function AboutToExit()
  309.    {
  310.       var _loc5_ = false;
  311.       var _loc6_ = Math.cos(3.141592653589793 * this._rotation / 180) * (this._width + 30 * this.numSpeed) + this._x;
  312.       var _loc8_ = Math.sin(3.141592653589793 * this._rotation / 180) * (this._width + 30 * this.numSpeed) + this._y;
  313.       var _loc7_ = 200;
  314.       var _loc4_ = _loc6_ - _root._xmouse;
  315.       var _loc3_ = _loc8_ - _root._ymouse;
  316.       if(Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_) > _loc7_)
  317.       {
  318.          _loc5_ = true;
  319.       }
  320.       return _loc5_;
  321.    }
  322.    function TurnOff()
  323.    {
  324.       this.enemyOff = true;
  325.    }
  326.    function TurnOn()
  327.    {
  328.       this.enemyOff = false;
  329.    }
  330. }
  331.