home *** CD-ROM | disk | FTP | other *** search
/ Champak 112 / jogo-disk-112.iso / Games / pixieland_puzzle.swf / scripts / __Packages / someFrogs / Puzzles / JigsawGroup.as next >
Text File  |  2010-07-14  |  6KB  |  171 lines

  1. class someFrogs.Puzzles.JigsawGroup extends someFrogs.Lake.MaskedPiece
  2. {
  3.    static var symbolName = "JigsawGroup";
  4.    static var symbolOwner = someFrogs.Puzzles.JigsawGroup;
  5.    var className = "JigsawGroup";
  6.    var pieces_count = 1;
  7.    var rot_steps = 4;
  8.    var enabled = false;
  9.    var active = false;
  10.    function JigsawGroup()
  11.    {
  12.       super();
  13.       this.rot_angle = 360 / this.rot_steps;
  14.       if(this.groupProps.ri == undefined)
  15.       {
  16.          this.groupProps.ri = 0;
  17.       }
  18.       this._x = this.groupProps.x;
  19.       this._y = this.groupProps.y;
  20.       this.rotateGroup(this.groupProps.ri);
  21.       this.ini_depth = this.getDepth();
  22.       this.setEnabled(this._parent.enabled);
  23.    }
  24.    function setEnabled(eFl)
  25.    {
  26.       if(this.enabled != eFl)
  27.       {
  28.          this.enabled = eFl;
  29.          var _loc2_ = new Color(this.pic_mc);
  30.          if(eFl)
  31.          {
  32.             _loc2_.setTransform({ra:100,ga:100,ba:100});
  33.             this.onPress = this.IamPressed;
  34.             this.onRelease = this.onReleaseOutside = this.IamReleased;
  35.          }
  36.          else
  37.          {
  38.             this.onPress = this.onRelease = this.onReleaseOutside = null;
  39.             _loc2_.setTransform(this._parent.disabled_color);
  40.             ┬º┬ºpush(this.stopDrag());
  41.          }
  42.       }
  43.    }
  44.    function IamPressed()
  45.    {
  46.       this._parent.childPressed(this);
  47.       this.startDrag(false,this.drag_area_fixed.l,this.drag_area_fixed.t,this.drag_area_fixed.r,this.drag_area_fixed.b);
  48.    }
  49.    function IamReleased()
  50.    {
  51.       this.put_me_to(this._x,this._y);
  52.       this._parent.childReleased(this);
  53.       this.stopDrag();
  54.    }
  55.    function blink(steps)
  56.    {
  57.       if(steps > 0)
  58.       {
  59.          this.blink_cnt = Number(steps);
  60.       }
  61.       if(this.blink_cnt > 0)
  62.       {
  63.          if(this.onEnterFrame != this.blink)
  64.          {
  65.             this.onEnterFrame = this.blink;
  66.          }
  67.          else
  68.          {
  69.             this.blink_cnt = this.blink_cnt - 1;
  70.             var _loc2_ = 50 * Math.sin(1.5 * this.blink_cnt);
  71.             this.blinkColor(_loc2_);
  72.          }
  73.       }
  74.       else
  75.       {
  76.          delete this.onEnterFrame;
  77.       }
  78.    }
  79.    function takeMe(obj)
  80.    {
  81.       if(obj != this)
  82.       {
  83.          this.extendMaskedArea(obj.piecesArr);
  84.          this.groupProps.xb = Math.min(this.groupProps.xb,obj.groupProps.xb);
  85.          this.groupProps.yb = Math.min(this.groupProps.yb,obj.groupProps.yb);
  86.          this.groupProps.xe = Math.max(this.groupProps.xe,obj.groupProps.xe);
  87.          this.groupProps.ye = Math.max(this.groupProps.ye,obj.groupProps.ye);
  88.          this.ini_depth = Math.min(this.ini_depth,obj.ini_depth);
  89.          this.pieces_count += obj.pieces_count;
  90.          this.put_me_to(this._x,this._y);
  91.       }
  92.    }
  93.    function rotateGroup(ccw)
  94.    {
  95.       this.put_me_to(this._x,this._y);
  96.       ccw = Math.abs(ccw) <= 0 ? 0 : ccw;
  97.       this.groupProps.ri = Math.round(ccw + this.groupProps.ri);
  98.       var _loc2_ = Math.floor(this.groupProps.ri / this.rot_steps);
  99.       if(_loc2_ != 0)
  100.       {
  101.          this.groupProps.ri -= _loc2_ * this.rot_steps;
  102.       }
  103.       var _loc3_ = this.rot_angle * this.groupProps.ri;
  104.       this._rotation = _loc3_;
  105.       var _loc4_ = this.rot_tranform(_loc3_,{cx:(this.groupProps.xb + this.groupProps.xe) / 2,cy:(this.groupProps.yb + this.groupProps.ye) / 2});
  106.       this.put_me_to(this.groupProps.x + _loc4_.x,this.groupProps.y + _loc4_.y);
  107.    }
  108.    function put_me_to(x, y)
  109.    {
  110.       this.displacement = this.rot_tranform(this._rotation,{cx:(this.groupProps.xb + this.groupProps.xe) / 2,cy:(this.groupProps.yb + this.groupProps.ye) / 2});
  111.       this.fix_drag_area();
  112.       x = Math.min(x,this.drag_area_fixed.r);
  113.       x = Math.max(x,this.drag_area_fixed.l);
  114.       y = Math.min(y,this.drag_area_fixed.b);
  115.       y = Math.max(y,this.drag_area_fixed.t);
  116.       this._x = x;
  117.       this._y = y;
  118.       this.groupProps.x = x - this.displacement.x;
  119.       this.groupProps.y = y - this.displacement.y;
  120.    }
  121.    function fix_drag_area(Void)
  122.    {
  123.       var _loc4_ = this.rot_angle * this.groupProps.ri;
  124.       var _loc3_ = this.rot_tranform(_loc4_,{cx:(this.groupProps.xe - this.groupProps.xb) / 2,cy:(this.groupProps.ye - this.groupProps.yb) / 2});
  125.       var _loc2_ = new Object();
  126.       _loc2_.xb = Math.min(this.groupProps.xb + _loc3_.x,this.groupProps.xe - _loc3_.x);
  127.       _loc2_.yb = Math.min(this.groupProps.yb + _loc3_.y,this.groupProps.ye - _loc3_.y);
  128.       _loc2_.xe = Math.max(this.groupProps.xb + _loc3_.x,this.groupProps.xe - _loc3_.x);
  129.       _loc2_.ye = Math.max(this.groupProps.yb + _loc3_.y,this.groupProps.ye - _loc3_.y);
  130.       this.drag_area_fixed = new Object();
  131.       this.drag_area_fixed.l = this._parent.dragArea.l + this.displacement.x - _loc2_.xb;
  132.       this.drag_area_fixed.t = this._parent.dragArea.t + this.displacement.y - _loc2_.yb;
  133.       this.drag_area_fixed.r = this._parent.dragArea.r + this.displacement.x - _loc2_.xe;
  134.       this.drag_area_fixed.b = this._parent.dragArea.b + this.displacement.y - _loc2_.ye;
  135.    }
  136.    function rot_tranform(a, to)
  137.    {
  138.       a = a * 3.141592653589793 / 180;
  139.       var _loc4_ = Math.atan(to.cy / to.cx);
  140.       var _loc3_ = Math.sqrt(Math.pow(to.cx,2) + Math.pow(to.cy,2));
  141.       return {x:to.cx - _loc3_ * Math.cos(a + _loc4_),y:to.cy - _loc3_ * Math.sin(a + _loc4_)};
  142.    }
  143.    function activeColor(act)
  144.    {
  145.       var _loc2_ = new Color(this.ground_mc);
  146.       if(act)
  147.       {
  148.          _loc2_.setRGB(Number(this.borderSelected));
  149.       }
  150.       else
  151.       {
  152.          _loc2_.setRGB(Number(this.border));
  153.       }
  154.    }
  155.    function blinkColor(vl)
  156.    {
  157.       var _loc3_ = new Color(this);
  158.       var _loc2_ = String(vl);
  159.       _loc3_.setTransform({rb:_loc2_,gb:_loc2_,bb:_loc2_});
  160.    }
  161.    function size(Void)
  162.    {
  163.       super.size();
  164.    }
  165.    function init(Void)
  166.    {
  167.       this.displacement = {x:0,y:0};
  168.       super.init();
  169.    }
  170. }
  171.