home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Puzzle / crazycube.swf / scripts / __Packages / com / Polygon.as < prev    next >
Encoding:
Text File  |  2006-06-13  |  11.6 KB  |  419 lines

  1. class com.Polygon
  2. {
  3.    var nodes;
  4.    var polySound;
  5.    var clickStatus;
  6.    var complite;
  7.    var stopPolygon;
  8.    var polyType;
  9.    var clip;
  10.    var obj;
  11.    var pass;
  12.    var poitsFound;
  13.    var i;
  14.    function Polygon(_clip, _typePolygon)
  15.    {
  16.       var _loc3_ = parseInt(_typePolygon,10);
  17.       this.nodes = new Array();
  18.       this.polySound = new com.Sounds(_clip);
  19.       this.clickStatus = false;
  20.       this.complite = false;
  21.       if(_typePolygon == undefined || _loc3_ < 1)
  22.       {
  23.          this.stopPolygon = false;
  24.          if(_loc3_ < 0)
  25.          {
  26.             this.polyType = new com.Types(_loc3_);
  27.          }
  28.          else
  29.          {
  30.             this.polyType = new com.Types(0);
  31.          }
  32.       }
  33.       else
  34.       {
  35.          _global.startPoint.push({poly:this,i:_global.polygons.length});
  36.          this.stopPolygon = true;
  37.          this.polyType = new com.Types(_loc3_);
  38.       }
  39.       this.clip = _clip;
  40.       this.clip.obj = this;
  41.       this.clip.useHandCursor = false;
  42.       this.clip.onPress = this.clickToPolygon;
  43.       this.clip.onRelease = this.clip.onReleaseOutside = this.deleteAutoSelect;
  44.    }
  45.    function addNode(a, b)
  46.    {
  47.       this.nodes.push({node:a,control:b});
  48.    }
  49.    function clickToPolygon()
  50.    {
  51.       _global.undoArray = new Array();
  52.       if(this.obj.stopPolygon)
  53.       {
  54.          this.obj.polySound.playSound("clickToEndPoint");
  55.          _global.selectType = this.obj.polyType.type;
  56.          this.obj.selectFace();
  57.       }
  58.       else if(_global.selectType > 0 && this.obj.polyType.type >= 0 && this.obj.polyType.type != _global.selectType)
  59.       {
  60.          _global.undoArray.push({poly:this.obj,type:this.obj.polyType.type});
  61.          this.obj.polySound.playSound("clickToFace");
  62.          this.obj.polyType.type = _global.selectType;
  63.       }
  64.       this.obj.draw();
  65.       this.obj.clip.onMouseMove = this.obj.autoSelect;
  66.    }
  67.    function autoSelect()
  68.    {
  69.       var _loc3_ = 3;
  70.       var _loc5_ = _global.polygons.length;
  71.       while(_loc3_ < _loc5_)
  72.       {
  73.          var _loc2_ = _global.polygons[_loc3_];
  74.          if(_loc2_.clip.hitTest(_xmouse,_ymouse,true))
  75.          {
  76.             if(_loc2_.polyType.type != _global.selectType)
  77.             {
  78.                if(!_loc2_.stopPolygon && _loc2_.polyType.type >= 0)
  79.                {
  80.                   _global.undoArray.push({poly:_loc2_,type:_loc2_.polyType.type});
  81.                   _loc2_.polyType.type = _global.selectType;
  82.                   _loc2_.polySound.playSound("clickToFace");
  83.                   _loc2_.draw();
  84.                   break;
  85.                }
  86.             }
  87.          }
  88.          _loc3_ = _loc3_ + 1;
  89.       }
  90.    }
  91.    function deleteAutoSelect()
  92.    {
  93.       delete this.obj.clip.onMouseMove;
  94.       if(_global.selectType > 0)
  95.       {
  96.          this.obj.checkStatusLines();
  97.       }
  98.    }
  99.    function selectFace()
  100.    {
  101.       this.polyType.oStatus = 1;
  102.       var _loc4_ = 0;
  103.       var _loc5_ = _global.startPoint.length;
  104.       while(_loc4_ < _loc5_)
  105.       {
  106.          var _loc3_ = _global.startPoint[_loc4_].poly;
  107.          if(_loc3_.polyType.type == this.polyType.type)
  108.          {
  109.             _loc3_.polyType.oStatus = 1;
  110.          }
  111.          else if(_loc3_.polyType.complite)
  112.          {
  113.             _loc3_.polyType.oStatus = 2;
  114.          }
  115.          else
  116.          {
  117.             _loc3_.polyType.oStatus = 0;
  118.          }
  119.          _loc3_.draw();
  120.          _loc4_ = _loc4_ + 1;
  121.       }
  122.    }
  123.    function changeStatusComlite(poly)
  124.    {
  125.       var _loc4_ = false;
  126.       if(!poly.polyType.complite)
  127.       {
  128.          var _loc3_ = 0;
  129.          var _loc5_ = _global.startPoint.length;
  130.          while(_loc3_ < _loc5_)
  131.          {
  132.             var _loc2_ = _global.startPoint[_loc3_].poly;
  133.             if(_loc2_.polyType.type == poly.polyType.type)
  134.             {
  135.                _loc2_.polyType.complite = true;
  136.                _loc2_.polyType.oStatus = 2;
  137.                _loc4_ = true;
  138.             }
  139.             _loc2_.draw();
  140.             _loc3_ = _loc3_ + 1;
  141.          }
  142.       }
  143.       return _loc4_;
  144.    }
  145.    function changeStatusNoComlite(poly)
  146.    {
  147.       var _loc4_ = false;
  148.       if(poly.polyType.complite)
  149.       {
  150.          var _loc3_ = 0;
  151.          var _loc5_ = _global.startPoint.length;
  152.          while(_loc3_ < _loc5_)
  153.          {
  154.             var _loc2_ = _global.startPoint[_loc3_].poly;
  155.             if(_loc2_.polyType.type == poly.polyType.type)
  156.             {
  157.                _loc2_.polyType.complite = false;
  158.                _loc2_.polyType.oStatus = 0;
  159.                _loc4_ = true;
  160.             }
  161.             _loc2_.draw();
  162.             _loc3_ = _loc3_ + 1;
  163.          }
  164.       }
  165.       return _loc4_;
  166.    }
  167.    function checkStatusLines()
  168.    {
  169.       var _loc9_ = false;
  170.       var _loc11_ = false;
  171.       var _loc10_ = 0;
  172.       var _loc12_ = _global.startPoint.length;
  173.       var _loc8_ = 1;
  174.       while(_loc8_ <= _loc12_ / 2)
  175.       {
  176.          var _loc4_ = 0;
  177.          this.pass = new Array();
  178.          this.poitsFound = new Array();
  179.          while(_loc4_ < _loc12_)
  180.          {
  181.             var _loc3_ = _global.startPoint[_loc4_].poly;
  182.             var _loc5_ = _loc8_.toString();
  183.             if(_loc3_.polyType.type == _loc5_)
  184.             {
  185.                this.poitsFound.push(_global.startPoint[_loc4_].i);
  186.                while(true)
  187.                {
  188.                   var _loc6_ = this.poitsFound.length;
  189.                   if(_loc6_ == 0)
  190.                   {
  191.                      if(this.changeStatusNoComlite(_loc3_))
  192.                      {
  193.                         _loc11_ = true;
  194.                      }
  195.                      break;
  196.                   }
  197.                   var _loc7_ = this.foundNextFace(this.poitsFound[0],_loc5_);
  198.                   if(_loc7_)
  199.                   {
  200.                      _loc10_ = _loc10_ + 1;
  201.                      if(this.changeStatusComlite(_loc3_))
  202.                      {
  203.                         _loc9_ = true;
  204.                      }
  205.                      break;
  206.                   }
  207.                }
  208.                break;
  209.             }
  210.             _loc4_ = _loc4_ + 1;
  211.          }
  212.          _loc8_ = _loc8_ + 1;
  213.       }
  214.       if(_loc11_)
  215.       {
  216.          this.polySound.playSound("lineNoComplite");
  217.       }
  218.       else if(_loc9_)
  219.       {
  220.          if(_loc10_ == _loc12_ / 2)
  221.          {
  222.             this.polySound.playSound("winLevel");
  223.             this.clip._parent._parent.endLevel();
  224.          }
  225.          else
  226.          {
  227.             this.polySound.playSound("lineComplite");
  228.          }
  229.       }
  230.    }
  231.    function foundNextFace(i, type)
  232.    {
  233.       var _loc10_ = false;
  234.       var _loc3_ = _global.amountFace;
  235.       var _loc7_ = _loc3_ * _loc3_;
  236.       var _loc14_ = i - 3;
  237.       var _loc5_ = int(_loc14_ / _loc7_);
  238.       var _loc9_ = Math.floor((_loc14_ - _loc5_ * _loc7_) / _loc3_);
  239.       var _loc8_ = _loc14_ % _loc3_;
  240.       var _loc15_ = _loc9_ - 1;
  241.       var _loc11_ = _loc8_;
  242.       if(_loc15_ < 0)
  243.       {
  244.          if(_loc5_ == 1)
  245.          {
  246.             _loc15_ = _loc3_ - _loc8_ - 1;
  247.             _loc11_ = _loc3_ - 1;
  248.          }
  249.          else
  250.          {
  251.             _loc15_ = _loc3_ - 1;
  252.          }
  253.          var _loc17_ = 0;
  254.          _loc17_ = _loc5_ == 0 ? 10 : _loc17_;
  255.       }
  256.       else
  257.       {
  258.          _loc17_ = _loc5_;
  259.       }
  260.       var _loc13_ = 3 + (_loc15_ * _loc3_ + _loc11_) + _loc17_ * _loc7_;
  261.       if(_global.polygons[_loc13_].polyType.type == type && !this.pass[_loc13_])
  262.       {
  263.          if(_global.polygons[_loc13_].stopPolygon)
  264.          {
  265.             _loc10_ = true;
  266.          }
  267.          else
  268.          {
  269.             this.pass[i] = true;
  270.             this.poitsFound.push(_loc13_);
  271.          }
  272.       }
  273.       _loc15_ = _loc9_ + 1;
  274.       _loc11_ = _loc8_;
  275.       if(_loc15_ >= _loc3_)
  276.       {
  277.          _loc15_ = 0;
  278.          _loc17_ = _loc5_ + 2;
  279.       }
  280.       else
  281.       {
  282.          _loc17_ = _loc5_;
  283.       }
  284.       _loc13_ = 3 + (_loc15_ * _loc3_ + _loc11_) + _loc17_ * _loc7_;
  285.       if(_global.polygons[_loc13_].polyType.type == type && !this.pass[_loc13_])
  286.       {
  287.          if(_global.polygons[_loc13_].stopPolygon)
  288.          {
  289.             _loc10_ = true;
  290.          }
  291.          else
  292.          {
  293.             this.pass[i] = true;
  294.             this.poitsFound.push(_loc13_);
  295.          }
  296.       }
  297.       _loc15_ = _loc9_;
  298.       _loc11_ = _loc8_ + 1;
  299.       if(_loc11_ >= _loc3_)
  300.       {
  301.          if(_loc5_ == 0)
  302.          {
  303.             _loc15_ = 0;
  304.             _loc11_ = _loc3_ - _loc9_ - 1;
  305.          }
  306.          else
  307.          {
  308.             _loc11_ = 0;
  309.          }
  310.          _loc17_ = 1;
  311.          _loc17_ = _loc5_ == 1 ? 10 : _loc17_;
  312.       }
  313.       else
  314.       {
  315.          _loc17_ = _loc5_;
  316.       }
  317.       _loc13_ = 3 + (_loc15_ * _loc3_ + _loc11_) + _loc17_ * _loc7_;
  318.       if(_global.polygons[_loc13_].polyType.type == type && !this.pass[_loc13_])
  319.       {
  320.          if(_global.polygons[_loc13_].stopPolygon)
  321.          {
  322.             _loc10_ = true;
  323.          }
  324.          else
  325.          {
  326.             this.pass[i] = true;
  327.             this.poitsFound.push(_loc13_);
  328.          }
  329.       }
  330.       _loc15_ = _loc9_;
  331.       _loc11_ = _loc8_ - 1;
  332.       if(_loc11_ < 0)
  333.       {
  334.          if(_loc5_ == 0)
  335.          {
  336.             _loc15_ = _loc3_ - 1;
  337.             _loc11_ = _loc3_ - _loc8_ - 1;
  338.          }
  339.          else
  340.          {
  341.             _loc11_ = _loc3_ - 1;
  342.          }
  343.          _loc17_ = 2;
  344.          _loc17_ = _loc5_ != 1 ? 10 : _loc17_;
  345.       }
  346.       else
  347.       {
  348.          _loc17_ = _loc5_;
  349.       }
  350.       _loc13_ = 3 + (_loc15_ * _loc3_ + _loc11_) + _loc17_ * _loc7_;
  351.       if(_global.polygons[_loc13_].polyType.type == type && !this.pass[_loc13_])
  352.       {
  353.          if(_global.polygons[_loc13_].stopPolygon)
  354.          {
  355.             _loc10_ = true;
  356.          }
  357.          else
  358.          {
  359.             this.pass[i] = true;
  360.             this.poitsFound.push(_loc13_);
  361.          }
  362.       }
  363.       for(var _loc12_ in this.poitsFound)
  364.       {
  365.          if(this.poitsFound[_loc12_] == i)
  366.          {
  367.             var _loc4_ = _loc12_;
  368.             this.poitsFound.splice(_loc4_,1);
  369.          }
  370.       }
  371.       return _loc10_;
  372.    }
  373.    function draw()
  374.    {
  375.       this.i = 1;
  376.       this.clip.clear();
  377.       var _loc5_ = (this.nodes[1].node.x - this.nodes[0].node.x) * (this.nodes[2].node.y - this.nodes[0].node.y) - (this.nodes[1].node.y - this.nodes[0].node.y) * (this.nodes[2].node.x - this.nodes[0].node.x);
  378.       if(_loc5_ < 0)
  379.       {
  380.          var _loc3_ = this.polyType.simpleStyle;
  381.          this.clip.moveTo(this.nodes[0].node.x,this.nodes[0].node.y);
  382.          if(_loc3_.linealpha != 0)
  383.          {
  384.             this.clip.lineStyle(_loc3_.lineweight,_loc3_.linecolor,_loc3_.linealpha);
  385.          }
  386.          this.clip.beginFill(_loc3_.fillcolor,_loc3_.fillalpha);
  387.          var _loc4_ = this.nodes.length;
  388.          while(this.i < _loc4_)
  389.          {
  390.             if(this.nodes[this.i].control)
  391.             {
  392.                var _loc2_ = this.polyType.advanceStyle;
  393.                this.clip.moveTo(this.nodes[this.i].node.x,this.nodes[this.i].node.y);
  394.                if(_loc2_.linealpha != 0)
  395.                {
  396.                   this.clip.lineStyle(_loc2_.lineweight,_loc2_.linecolor,_loc2_.linealpha);
  397.                }
  398.                this.clip.beginFill(_loc2_.fillcolor,_loc2_.fillalpha);
  399.                this.i = this.i + 1;
  400.             }
  401.             else
  402.             {
  403.                this.clip.lineTo(this.nodes[this.i].node.x,this.nodes[this.i].node.y);
  404.                this.i = this.i + 1;
  405.             }
  406.          }
  407.          this.clip.endFill();
  408.       }
  409.    }
  410.    function set type(a)
  411.    {
  412.       this.polyType = a;
  413.    }
  414.    function get type()
  415.    {
  416.       return this.polyType;
  417.    }
  418. }
  419.