home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Puzzle / jig.swf / scripts / __Packages / JigPiece.as < prev    next >
Encoding:
Text File  |  2006-06-13  |  5.3 KB  |  244 lines

  1. class JigPiece
  2. {
  3.    var ┬ºset┬º;
  4.    var id;
  5.    var clip;
  6.    var sec;
  7.    var rot;
  8.    var y;
  9.    var x;
  10.    var dot;
  11.    function JigPiece()
  12.    {
  13.    }
  14.    function Create(┬ºset┬º, id, top, right, bottom, left)
  15.    {
  16.       this["set"] = ┬ºset┬º;
  17.       this.id = id;
  18.       this.clip = ┬ºset┬º.clip.attachMovie("Piece","piece" + id,id);
  19.       this.sec = new Array(-1,-1,-1,-1);
  20.       this.LoadSec(0,top);
  21.       this.LoadSec(1,right);
  22.       this.LoadSec(2,bottom);
  23.       this.LoadSec(3,left);
  24.       this.rot = 0;
  25.       this.clip._alpha = 0;
  26.    }
  27.    function Destroy()
  28.    {
  29.       this.clip.removeMovieClip();
  30.       this.sec = new Array();
  31.       this["set"] = undefined;
  32.    }
  33.    function Toggle()
  34.    {
  35.       if(this.clip._alpha > 0)
  36.       {
  37.          this.clip._alpha = 0;
  38.       }
  39.       else
  40.       {
  41.          this.clip._alpha = 100;
  42.       }
  43.    }
  44.    function Show()
  45.    {
  46.       this.clip._alpha = 100;
  47.    }
  48.    function ShowLabel()
  49.    {
  50.       this.clip.top.seclabel._alpha = 100;
  51.       this.clip.right.seclabel._alpha = 100;
  52.       this.clip.bottom.seclabel._alpha = 100;
  53.       this.clip.left.seclabel._alpha = 100;
  54.    }
  55.    function Begin()
  56.    {
  57.       this.SetPosition(_root.randomindex(this["set"].freecols),-2);
  58.       this.Show();
  59.    }
  60.    function NextPiece()
  61.    {
  62.       this.clip._x = 481;
  63.       this.clip._y = 39.7;
  64.       this.Show();
  65.    }
  66.    function GetLocalSec(orient)
  67.    {
  68.       var _loc2_ = orient - this.rot;
  69.       if(_loc2_ < 0)
  70.       {
  71.          _loc2_ = 4 + _loc2_;
  72.       }
  73.       return _loc2_ % 4;
  74.    }
  75.    function GetLocalValue(orient)
  76.    {
  77.       return this.sec[this.GetLocalSec(orient)];
  78.    }
  79.    function GetNormal(orient)
  80.    {
  81.       switch(orient)
  82.       {
  83.          case 0:
  84.             return new Array(0,-1);
  85.          case 1:
  86.             return new Array(1,0);
  87.          case 2:
  88.             return new Array(0,1);
  89.          case 3:
  90.             return new Array(-1,0);
  91.          default:
  92.       }
  93.    }
  94.    function GetAdjacent()
  95.    {
  96.       var _loc2_ = new Array();
  97.       _loc2_[3] = this.GetAdjacentLeft();
  98.       _loc2_[1] = this.GetAdjacentRight();
  99.       if(this.y != this["set"].height - 1)
  100.       {
  101.          _loc2_[2] = this["set"].stack[this.x][this["set"].height - this.y - 2];
  102.       }
  103.       if(this["set"].stack[this.x].length >= this["set"].height - this.y)
  104.       {
  105.          _loc2_[0] = this["set"].stack[this.x][this["set"].height - this.y];
  106.       }
  107.       return _loc2_;
  108.    }
  109.    function GetAdjacentLeft()
  110.    {
  111.       if(this.x > 0)
  112.       {
  113.          return this["set"].stack[this.x - 1][this["set"].height - this.y - 1];
  114.       }
  115.       return undefined;
  116.    }
  117.    function GetAdjacentRight()
  118.    {
  119.       if(this.x < this["set"].width - 1)
  120.       {
  121.          return this["set"].stack[this.x + 1][this["set"].height - this.y - 1];
  122.       }
  123.       return undefined;
  124.    }
  125.    function OrientName(orient)
  126.    {
  127.       var _loc1_ = new Array("top","right","bottom","left");
  128.       return _loc1_[orient];
  129.    }
  130.    function LoadSec(orient, val)
  131.    {
  132.       var _loc3_ = undefined;
  133.       var _loc4_ = undefined;
  134.       _loc4_ = this.OrientName(orient);
  135.       _loc3_ = orient * 90;
  136.       this.sec[orient] = val;
  137.       var _loc6_ = new Array("flat","tri-out","tri-in");
  138.       if(val < 0)
  139.       {
  140.          this.clip[_loc4_].removeMovieClip();
  141.          return undefined;
  142.       }
  143.       var _loc2_ = this.clip.attachMovie("sec-" + _loc6_[val],_loc4_,_loc3_);
  144.       _loc2_._rotation = _loc3_;
  145.       _loc2_.seclabel.text.text = orient;
  146.    }
  147.    function Hide()
  148.    {
  149.       this.clip._alpha = 0;
  150.    }
  151.    function Window()
  152.    {
  153.       this.clip.top.gotoAndStop(2);
  154.       this.clip.right.gotoAndStop(2);
  155.       this.clip.bottom.gotoAndStop(2);
  156.       this.clip.left.gotoAndStop(2);
  157.    }
  158.    function Flaw()
  159.    {
  160.       this.clip.top.gotoAndStop(3);
  161.       this.clip.right.gotoAndStop(3);
  162.       this.clip.bottom.gotoAndStop(3);
  163.       this.clip.left.gotoAndStop(3);
  164.    }
  165.    function Dot(orient)
  166.    {
  167.       if(this.dot != undefined)
  168.       {
  169.          this.dot.removeMovieClip();
  170.       }
  171.       this.dot = this.clip[this.OrientName(orient)].attachMovie("Dot","dot",0);
  172.       this.dot._y = -10;
  173.    }
  174.    function Mark()
  175.    {
  176.       this.clip.attachMovie("Dot","mark",100);
  177.    }
  178.    function Unmark()
  179.    {
  180.       if(this.clip.mark)
  181.       {
  182.          this.clip.mark.removeMovieClip();
  183.       }
  184.    }
  185.    function GlobalY(y)
  186.    {
  187.       return this["set"].offy + this["set"].psizey * y;
  188.    }
  189.    function GlobalX(x)
  190.    {
  191.       return this["set"].offx + this["set"].psizex * x;
  192.    }
  193.    function SetY(y)
  194.    {
  195.       this.y = y;
  196.       this.clip._y = this.GlobalY(y);
  197.    }
  198.    function SetX(x)
  199.    {
  200.       this.x = x;
  201.       this.clip._x = this.GlobalX(x);
  202.    }
  203.    function SetPosition(x, y)
  204.    {
  205.       if(x != -1)
  206.       {
  207.          this.SetX(x);
  208.       }
  209.       if(y != -1)
  210.       {
  211.          this.SetY(y);
  212.       }
  213.    }
  214.    function AddPosition(x, y)
  215.    {
  216.       if(x)
  217.       {
  218.          this.SetX(this.x + x);
  219.       }
  220.       if(y)
  221.       {
  222.          this.SetY(this.y + y);
  223.       }
  224.    }
  225.    function SetRotation(r)
  226.    {
  227.       if(r < 0)
  228.       {
  229.          r = 4 + r;
  230.       }
  231.       this.rot = r % 4;
  232.       this.clip._rotation = this.rot * 90;
  233.    }
  234.    function AddRotation(r)
  235.    {
  236.       if(r < 0)
  237.       {
  238.          r = 4 + r;
  239.       }
  240.       this.rot = (this.rot + r) % 4;
  241.       this.clip._rotation = this.rot * 90;
  242.    }
  243. }
  244.