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

  1. class Bubblefield
  2. {
  3.    var arrUnits;
  4.    var x;
  5.    var y;
  6.    var blnBoss;
  7.    function Bubblefield()
  8.    {
  9.       this.arrUnits = new Array();
  10.       this.x = 0;
  11.       this.y = 0;
  12.       this.blnBoss = false;
  13.    }
  14.    function GetNumUnits()
  15.    {
  16.       return this.arrUnits.length;
  17.    }
  18.    function AddUnit(myName, myLinkage, myPosition, myDepth)
  19.    {
  20.       var _loc2_ = new BubblefieldUnit(myName,myLinkage,myPosition,myDepth);
  21.       this.arrUnits.push(_loc2_);
  22.    }
  23.    function AddSpawnedUnit(myName, myLinkage, myPosition, myDepth)
  24.    {
  25.       var _loc4_ = new BubblefieldUnit(myName,myLinkage,myPosition,myDepth);
  26.       _loc4_._position._x = myPosition._x - (_root.bg._x - _root.avatar._x) - 250;
  27.       _loc4_._position._y = myPosition._y - (_root.bg._y - _root.avatar._y) - 200;
  28.       this.arrUnits.push(_loc4_);
  29.    }
  30.    function AddUnitAndList(myName, myLinkage, myPosition, myDepth, formalName)
  31.    {
  32.       var _loc2_ = new BubblefieldUnit(myName,myLinkage,myPosition,myDepth);
  33.       _loc2_._formalName = formalName;
  34.       this.arrUnits.push(_loc2_);
  35.    }
  36.    function MoveAllBubblefieldUnits(moveVector)
  37.    {
  38.       var _loc3_ = 0;
  39.       while(_loc3_ < this.arrUnits.length)
  40.       {
  41.          _root[this.arrUnits[_loc3_]._name]._x += moveVector._x;
  42.          _root[this.arrUnits[_loc3_]._name]._y += moveVector._y;
  43.          _loc3_ = _loc3_ + 1;
  44.       }
  45.    }
  46.    function GetClosestUnit(testX, testY)
  47.    {
  48.       var _loc7_ = 99999999;
  49.       var _loc6_ = 0;
  50.       var _loc8_ = "";
  51.       var _loc3_ = 0;
  52.       while(_loc3_ < this.arrUnits.length)
  53.       {
  54.          var _loc5_ = _root[this.arrUnits[_loc3_]._name]._x - testX;
  55.          var _loc4_ = _root[this.arrUnits[_loc3_]._name]._y - testY;
  56.          _loc6_ = Math.sqrt(_loc5_ * _loc5_ + _loc4_ * _loc4_);
  57.          if(_loc6_ < _loc7_)
  58.          {
  59.             _loc7_ = _loc6_;
  60.             _loc8_ = this.arrUnits[_loc3_]._name;
  61.          }
  62.          _loc3_ = _loc3_ + 1;
  63.       }
  64.       return _loc8_;
  65.    }
  66.    function GetUnitsWithinDistance(testX, testY, testDistance)
  67.    {
  68.       var _loc6_ = 0;
  69.       var _loc7_ = new Array();
  70.       var _loc3_ = 0;
  71.       while(_loc3_ < this.arrUnits.length)
  72.       {
  73.          var _loc5_ = _root[this.arrUnits[_loc3_]._name]._x - testX;
  74.          var _loc4_ = _root[this.arrUnits[_loc3_]._name]._y - testY;
  75.          _loc6_ = Math.sqrt(_loc5_ * _loc5_ + _loc4_ * _loc4_);
  76.          if(_loc6_ <= testDistance)
  77.          {
  78.             _loc7_.push(this.arrUnits[_loc3_]._name);
  79.          }
  80.          _loc3_ = _loc3_ + 1;
  81.       }
  82.       return _loc7_;
  83.    }
  84.    function RemoveUnit(unitName)
  85.    {
  86.       var _loc2_ = 0;
  87.       while(_loc2_ < this.arrUnits.length)
  88.       {
  89.          if(unitName == this.arrUnits[_loc2_]._name)
  90.          {
  91.             this.arrUnits.splice(_loc2_,1);
  92.             break;
  93.          }
  94.          _loc2_ = _loc2_ + 1;
  95.       }
  96.    }
  97.    function GetUnitType(unitName)
  98.    {
  99.       var _loc2_ = 0;
  100.       while(_loc2_ < this.arrUnits.length)
  101.       {
  102.          if(unitName == this.arrUnits[_loc2_]._name)
  103.          {
  104.             return this.arrUnits[_loc2_]._linkage;
  105.          }
  106.          _loc2_ = _loc2_ + 1;
  107.       }
  108.    }
  109.    function RemoveUnitByType(unitType, blnRemoveAll)
  110.    {
  111.       if(blnRemoveAll == true)
  112.       {
  113.          var _loc3_ = true;
  114.          while(_loc3_ == true)
  115.          {
  116.             _loc3_ = false;
  117.             var _loc2_ = 0;
  118.             while(_loc2_ < this.arrUnits.length)
  119.             {
  120.                if(unitType == this.arrUnits[_loc2_]._linkage)
  121.                {
  122.                   this.arrUnits.splice(_loc2_,1);
  123.                   _loc3_ = true;
  124.                   break;
  125.                }
  126.                _loc2_ = _loc2_ + 1;
  127.             }
  128.          }
  129.       }
  130.       else
  131.       {
  132.          _loc2_ = 0;
  133.          while(_loc2_ < this.arrUnits.length)
  134.          {
  135.             if(unitType == this.arrUnits[_loc2_]._linkage)
  136.             {
  137.                this.arrUnits.splice(_loc2_,1);
  138.                break;
  139.             }
  140.             _loc2_ = _loc2_ + 1;
  141.          }
  142.       }
  143.    }
  144.    function BuildUnitList()
  145.    {
  146.       var _loc3_ = new Array();
  147.       var _loc4_ = 0;
  148.       while(_loc4_ < this.arrUnits.length)
  149.       {
  150.          var _loc5_ = false;
  151.          var _loc6_ = false;
  152.          var _loc2_ = 0;
  153.          while(_loc2_ < _loc3_.length)
  154.          {
  155.             if(_loc3_[_loc2_].type == this.arrUnits[_loc4_]._linkage)
  156.             {
  157.                _loc3_[_loc2_].num = _loc3_[_loc2_].num + 1;
  158.                _loc5_ = true;
  159.                break;
  160.             }
  161.             _loc2_ = _loc2_ + 1;
  162.          }
  163.          if(_loc5_ == false)
  164.          {
  165.             if(_loc3_.length < 4)
  166.             {
  167.                _loc3_.push({name:this.arrUnits[_loc4_]._formalName,type:this.arrUnits[_loc4_]._linkage,num:1});
  168.             }
  169.             else
  170.             {
  171.                _loc6_ = true;
  172.             }
  173.          }
  174.          _loc4_ = _loc4_ + 1;
  175.       }
  176.       return _loc3_;
  177.    }
  178.    function HaltUnits()
  179.    {
  180.       var _loc3_ = 0;
  181.       while(_loc3_ < this.arrUnits.length)
  182.       {
  183.          _root[this.arrUnits[_loc3_]._name].TurnOff();
  184.          _loc3_ = _loc3_ + 1;
  185.       }
  186.    }
  187.    function ResumeUnits()
  188.    {
  189.       var _loc3_ = 0;
  190.       while(_loc3_ < this.arrUnits.length)
  191.       {
  192.          _root[this.arrUnits[_loc3_]._name].TurnOn();
  193.          _loc3_ = _loc3_ + 1;
  194.       }
  195.    }
  196.    function HideAllUnits()
  197.    {
  198.       var _loc4_ = new Array();
  199.       var _loc3_ = 0;
  200.       while(_loc3_ < this.arrUnits.length)
  201.       {
  202.          if(_root[this.arrUnits[_loc3_]._name]._type != 1)
  203.          {
  204.             _loc4_.push(this.arrUnits[_loc3_]._name);
  205.          }
  206.          else
  207.          {
  208.             this.arrUnits[_loc3_]._rotation = _root[this.arrUnits[_loc3_]._name]._rotation;
  209.          }
  210.          _root[this.arrUnits[_loc3_]._name].removeMovieClip();
  211.          _loc3_ = _loc3_ + 1;
  212.       }
  213.       _loc3_ = 0;
  214.       while(_loc3_ < _loc4_.length)
  215.       {
  216.          this.RemoveUnit(_loc4_[_loc3_]);
  217.          _loc3_ = _loc3_ + 1;
  218.       }
  219.    }
  220.    function ShowAllUnits(offsetVector)
  221.    {
  222.       var _loc3_ = 0;
  223.       while(_loc3_ < this.arrUnits.length)
  224.       {
  225.          _root.attachMovie(this.arrUnits[_loc3_]._linkage,this.arrUnits[_loc3_]._name,this.arrUnits[_loc3_]._depth);
  226.          _root[this.arrUnits[_loc3_]._name]._x = _root.bg._x + this.arrUnits[_loc3_]._position._x + offsetVector._x;
  227.          _root[this.arrUnits[_loc3_]._name]._y = _root.bg._y + this.arrUnits[_loc3_]._position._y + offsetVector._y;
  228.          _root[this.arrUnits[_loc3_]._name]._rotation = this.arrUnits[_loc3_]._rotation;
  229.          _loc3_ = _loc3_ + 1;
  230.       }
  231.    }
  232.    function CheckForHits(bulletName)
  233.    {
  234.       var _loc7_ = false;
  235.       var _loc6_ = undefined;
  236.       var _loc4_ = this.arrUnits.slice();
  237.       if(_root[bulletName]._type != 7)
  238.       {
  239.          var _loc5_ = 0;
  240.          while(_loc5_ < _loc4_.length)
  241.          {
  242.             _loc6_ = false;
  243.             if(_loc4_[_loc5_]._linkage == "Enemy_Leecher")
  244.             {
  245.                if(_root[_loc4_[_loc5_]._name].guy.hitTest(_root[bulletName]._x,_root[bulletName]._y,true))
  246.                {
  247.                   _loc7_ = true;
  248.                   _loc6_ = true;
  249.                }
  250.             }
  251.             else if(_root[_loc4_[_loc5_]._name].hitTest(_root[bulletName]._x,_root[bulletName]._y,true))
  252.             {
  253.                if(_root[bulletName].GetImmune(_loc4_[_loc5_]._name) == false)
  254.                {
  255.                   _loc7_ = true;
  256.                   _loc6_ = true;
  257.                   _root[bulletName].EventHitEnemy(_loc4_[_loc5_]._name);
  258.                   _root[bulletName].AddImmunity(_loc4_[_loc5_]._name);
  259.                }
  260.             }
  261.             if(_loc6_ == false)
  262.             {
  263.                var _loc11_ = _root[bulletName]._x - _root[bulletName].moveX * 0.5;
  264.                var _loc10_ = _root[bulletName]._y - _root[bulletName].moveY * 0.5;
  265.                if(_loc4_[_loc5_]._linkage == "Enemy_Leecher")
  266.                {
  267.                   if(_root[_loc4_[_loc5_]._name].guy.hitTest(_loc11_,_loc10_,true))
  268.                   {
  269.                      _loc7_ = true;
  270.                      _loc6_ = true;
  271.                   }
  272.                }
  273.                else if(_root[_loc4_[_loc5_]._name].hitTest(_loc11_,_loc10_,true))
  274.                {
  275.                   if(_root[bulletName].GetImmune(_loc4_[_loc5_]._name) == false)
  276.                   {
  277.                      _loc7_ = true;
  278.                      _loc6_ = true;
  279.                      _root[bulletName].EventHitEnemy(_loc4_[_loc5_]._name);
  280.                      _root[bulletName].AddImmunity(_loc4_[_loc5_]._name);
  281.                   }
  282.                }
  283.             }
  284.             if(_loc6_ == true)
  285.             {
  286.                _root[_loc4_[_loc5_]._name].ReceiveDamage(_root[bulletName]._damage,bulletName);
  287.             }
  288.             _loc5_ = _loc5_ + 1;
  289.          }
  290.       }
  291.       else
  292.       {
  293.          var _loc13_ = _root[bulletName]._width / 2 + 10;
  294.          _loc5_ = 0;
  295.          while(_loc5_ < _loc4_.length)
  296.          {
  297.             if(_root[bulletName].GetImmune(_loc4_[_loc5_]._name) == false)
  298.             {
  299.                var _loc9_ = _root[_loc4_[_loc5_]._name]._x - _root[bulletName]._x;
  300.                var _loc8_ = _root[_loc4_[_loc5_]._name]._y - _root[bulletName]._y;
  301.                var _loc12_ = Math.sqrt(_loc9_ * _loc9_ + _loc8_ * _loc8_);
  302.                if(_loc12_ <= _loc13_)
  303.                {
  304.                   if(_root[bulletName].GetImmune(_loc4_[_loc5_]._name) == false)
  305.                   {
  306.                      _loc7_ = true;
  307.                      _loc6_ = true;
  308.                      _root[bulletName].EventHitEnemy(_loc4_[_loc5_]._name);
  309.                      _root[bulletName].AddImmunity(_loc4_[_loc5_]._name);
  310.                   }
  311.                }
  312.             }
  313.             _loc5_ = _loc5_ + 1;
  314.          }
  315.       }
  316.       false;
  317.       return _loc7_;
  318.    }
  319.    function ConvertDrones()
  320.    {
  321.       var _loc4_ = new Array();
  322.       var _loc3_ = 0;
  323.       while(_loc3_ < this.arrUnits.length)
  324.       {
  325.          if(_root[this.arrUnits[_loc3_]._name]._type != 1)
  326.          {
  327.             _root.game.SpawnSeeker(_root[this.arrUnits[_loc3_]._name]._x,_root[this.arrUnits[_loc3_]._name]._y,7,_root[this.arrUnits[_loc3_]._name]._type);
  328.             _loc4_.push(this.arrUnits[_loc3_]._name);
  329.          }
  330.          _loc3_ = _loc3_ + 1;
  331.       }
  332.       _loc3_ = 0;
  333.       while(_loc3_ < _loc4_.length)
  334.       {
  335.          _root[_loc4_[_loc3_]].ReceiveDamage(999999,"");
  336.          _loc3_ = _loc3_ + 1;
  337.       }
  338.    }
  339.    function EstimateDifficulty()
  340.    {
  341.       var _loc3_ = 0;
  342.       var _loc2_ = 0;
  343.       while(_loc2_ < this.arrUnits.length)
  344.       {
  345.          if(this.arrUnits[_loc2_]._linkage == "Enemy_1")
  346.          {
  347.             _loc3_ += -0.2;
  348.          }
  349.          else if(this.arrUnits[_loc2_]._linkage == "Enemy_4")
  350.          {
  351.             _loc3_ += -0.02;
  352.          }
  353.          else if(this.arrUnits[_loc2_]._linkage == "Enemy_17")
  354.          {
  355.             _loc3_ += -0.2;
  356.          }
  357.          else if(this.arrUnits[_loc2_]._linkage == "Enemy_18")
  358.          {
  359.             _loc3_ += -0.2;
  360.          }
  361.          else if(this.arrUnits[_loc2_]._linkage == "Enemy_10")
  362.          {
  363.             _loc3_ += -2;
  364.          }
  365.          else if(this.arrUnits[_loc2_]._linkage == "Enemy_92")
  366.          {
  367.             _loc3_ += -4;
  368.          }
  369.          else
  370.          {
  371.             _loc3_ += 1;
  372.          }
  373.          _loc2_ = _loc2_ + 1;
  374.       }
  375.       return _loc3_;
  376.    }
  377. }
  378.