home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Puzzle / blobs.swf / scripts / DefineSprite_81 / frame_2 / DoAction.as
Encoding:
Text File  |  2006-06-13  |  12.7 KB  |  333 lines

  1. function GetLevelInfo(lvl)
  2. {
  3.    var levelinfo = new Array();
  4.    levelinfo = blevel[lvl].split("#");
  5.    standcount = levelinfo[0];
  6.    stand_x = levelinfo[1];
  7.    stand_y = levelinfo[2];
  8.    blobcount = levelinfo[3];
  9.    blob_x = levelinfo[4];
  10.    blob_y = levelinfo[5];
  11. }
  12. function NextLevel(dir)
  13. {
  14.    already.gotoAndStop("off");
  15.    level += dir;
  16.    if(levels < level)
  17.    {
  18.       level = 1;
  19.    }
  20.    if(level < 1)
  21.    {
  22.       level = levels;
  23.    }
  24.    ClearLevel();
  25.    if(completed == levels)
  26.    {
  27.       gotoAndPlay(73);
  28.    }
  29.    else
  30.    {
  31.       _parent.controls.levind = level + " of " + levels;
  32.       gotoAndPlay(5);
  33.    }
  34. }
  35. function DisplayProgress()
  36. {
  37.    if(completed == 1)
  38.    {
  39.       s = "";
  40.    }
  41.    else
  42.    {
  43.       s = "S";
  44.    }
  45.    _parent.progress = completed + " LEVEL" + s + " COMPLETED";
  46. }
  47. function SaveProgress()
  48. {
  49.    _parent.progress_string = completedlevels.toString();
  50.    fscommand("save","blobs.dat");
  51. }
  52. function LoadProgress(pstring)
  53. {
  54.    if(1 < pstring.length)
  55.    {
  56.       completedlevels = pstring.split(",");
  57.       j = 1;
  58.       while(completedlevels.length >= j)
  59.       {
  60.          completed += Number(completedlevels[j]);
  61.          j++;
  62.       }
  63.    }
  64.    DisplayProgress();
  65. }
  66. function ClearLevel()
  67. {
  68.    var x;
  69.    var y;
  70.    var stand;
  71.    var i = 0;
  72.    while(i < stand_x.length)
  73.    {
  74.       x = stand_x.charAt(i);
  75.       y = stand_y.charAt(i);
  76.       stand = "s" + x + y;
  77.       if(this[stand].blob != "")
  78.       {
  79.          this[this[stand].blob].removeMovieClip();
  80.       }
  81.       this[stand].removeMovieClip();
  82.       i++;
  83.    }
  84. }
  85. function checkDrop()
  86. {
  87.    var x = Number(this[cb].x);
  88.    var y = Number(this[cb].y);
  89.    var droptarget = this[cb]._droptarget.substr(6,3);
  90.    var dropx = this[droptarget].x;
  91.    var dropy = this[droptarget].y;
  92.    var origstand = "s" + x + y;
  93.    if(droptarget.indexOf("s") == -1 || droptarget == null || droptarget == origstand)
  94.    {
  95.       ReturnBlob(cb,origstand);
  96.       return undefined;
  97.    }
  98.    if(this[droptarget].inhabited == 1)
  99.    {
  100.       ReturnBlob(cb,origstand);
  101.       return undefined;
  102.    }
  103.    var dx = dropx - x;
  104.    var dy = dropy - y;
  105.    if(Math.abs(dx) == 2 || Math.abs(dy) == 2)
  106.    {
  107.       var middlex = x + dx / 2;
  108.       var middley = y + dy / 2;
  109.       var middlestand = "s" + middlex + middley;
  110.       if(this[middlestand].inhabited == 1)
  111.       {
  112.          middleblob = this[middlestand].blob;
  113.          this[middlestand].inhabited = 0;
  114.          this[middlestand].blob = "";
  115.          this[droptarget].blob = cb;
  116.          this[droptarget].inhabited = 1;
  117.          this[origstand].inhabited = 0;
  118.          this[origstand].blob = "";
  119.          this[middleblob].gotoAndPlay("die");
  120.          this[cb].x = dropx;
  121.          this[cb].y = dropy;
  122.          ReturnBlob(cb,droptarget);
  123.          blobcount--;
  124.          if(blobcount == 1)
  125.          {
  126.             winLevel(droptarget);
  127.          }
  128.          else if(checkForMoves() == false)
  129.          {
  130.             ResetLevel();
  131.          }
  132.       }
  133.       else
  134.       {
  135.          ReturnBlob(cb,origstand);
  136.       }
  137.    }
  138.    else
  139.    {
  140.       ReturnBlob(cb,origstand);
  141.    }
  142. }
  143. function ResetLevel()
  144. {
  145.    gotoAndPlay(16);
  146. }
  147. function checkForMoves()
  148. {
  149.    var j;
  150.    var x;
  151.    var y;
  152.    var i;
  153.    var k;
  154.    var cstand;
  155.    j = 0;
  156.    while(j < standcount)
  157.    {
  158.       x = Number(stand_x.charAt(j));
  159.       y = Number(stand_y.charAt(j));
  160.       cstand = "s" + x + y;
  161.       if(this[cstand].blob != "")
  162.       {
  163.          i = -1;
  164.          while(1 >= i)
  165.          {
  166.             k = -1;
  167.             while(1 >= k)
  168.             {
  169.                first = "s" + (x + k) + (y + i);
  170.                second = "s" + (x + k + k) + (y + i + i);
  171.                if(this[first].inhabited == 1 && this[second].inhabited == 0)
  172.                {
  173.                   return true;
  174.                }
  175.                k++;
  176.             }
  177.             i++;
  178.          }
  179.       }
  180.       j++;
  181.    }
  182.    return false;
  183. }
  184. function winLevel(dt)
  185. {
  186.    if(completedlevels[level] != 1)
  187.    {
  188.       completedlevels[level] = 1;
  189.       completed++;
  190.       DisplayProgress();
  191.    }
  192.    this[cb].gotoAndPlay("win");
  193.    this[cb].blob.gotoAndPlay("win");
  194.    this[dt].gotoAndPlay("win");
  195. }
  196. function ReturnBlob(rb, rs)
  197. {
  198.    this[rb]._x = this[rb].x * xinc + init_x;
  199.    this[rb]._y = this[rb].y * yinc + init_y;
  200.    this[rs].gotoAndPlay("hover");
  201.    this[rb].gotoAndPlay("hover");
  202. }
  203. function SetUpBoard()
  204. {
  205.    var i;
  206.    var x;
  207.    var y;
  208.    var newname;
  209.    var standname;
  210.    init_x = -254;
  211.    init_y = -180;
  212.    xinc = 50;
  213.    yinc = 30;
  214.    hidepth = 201;
  215.    i = 0;
  216.    while(i < standcount)
  217.    {
  218.       x = stand_x.charAt(i);
  219.       y = stand_y.charAt(i);
  220.       newname = "s" + x + y;
  221.       duplicateMovieClip("stand",newname,16384 + (i + 1));
  222.       this[newname]._x = init_x + x * xinc;
  223.       this[newname]._y = init_y + y * yinc;
  224.       this[newname].inhabited = 0;
  225.       this[newname].blob = "";
  226.       this[newname].x = x;
  227.       this[newname].y = y;
  228.       i++;
  229.    }
  230.    i = 0;
  231.    while(i < blobcount)
  232.    {
  233.       x = blob_x.charAt(i);
  234.       y = blob_y.charAt(i);
  235.       newname = "b" + x + y;
  236.       standname = "s" + x + y;
  237.       duplicateMovieClip("origblob",newname,16384 + hidepth++);
  238.       this[newname].x = x;
  239.       this[newname].y = y;
  240.       this[newname]._x = init_x + x * xinc;
  241.       this[newname]._y = init_y + y * yinc;
  242.       this[standname].inhabited = 1;
  243.       this[standname].blob = newname;
  244.       this[newname].blob.eyes.gotoAndPlay(random(90) + 1);
  245.       if(completedlevels[level])
  246.       {
  247.          grid.gotoAndStop(2);
  248.          already.gotoAndPlay("on");
  249.       }
  250.       else
  251.       {
  252.          grid.gotoAndStop(1);
  253.       }
  254.       i++;
  255.    }
  256. }
  257. function toggleBlobs(mode)
  258. {
  259.    var i;
  260.    var x;
  261.    var y;
  262.    var blobname;
  263.    i = 0;
  264.    while(i < blob_x.length)
  265.    {
  266.       x = blob_x.charAt(i);
  267.       y = blob_y.charAt(i);
  268.       blobname = "b" + x + y;
  269.       if(blobname != cb)
  270.       {
  271.          this[blobname].gotoAndStop(mode);
  272.       }
  273.       i++;
  274.    }
  275. }
  276. function EasterEgg()
  277. {
  278.    blevel[5] = "35#56756756756756723567235672345673456#11122233344455566666777778888889999#0###";
  279.    blevel[6] = "40#3456345673456734673456345673467345673456#1111222223333344445555666667777888889999#0###";
  280.    blevel[7] = "35#34567345674564564564564563456734567#11111222223334445556667778888899999#0###";
  281.    blevel[8] = "37#3456345673456734673463456346734673467#1111222223333344445556666777788889999#0###";
  282.    blevel[9] = "38#34563456734673467346734673467345673456#11112222233334444555566667777888889999#0###";
  283. }
  284. blevel = new Array();
  285. blevel[1] = "13#4645645645646#3344455566677#8#44564564#34445557#";
  286. blevel[2] = "16#4545674567456767#3344445555666677#10#4557675767#3344556677#";
  287. blevel[3] = "13#5456345674565#3444555556667#11#54563467465#34445555667#";
  288. blevel[4] = "32#12893752345673456783456785371289#11112234444445555556666667889999#8#34346767#44555566#";
  289. blevel[5] = "41#19245684562345678234567823456784562456819#11222223334444444555555566666667778888899#11#45645645646#22233344455#";
  290. blevel[6] = "33#456456234567823456782345678456456#222333444444455555556666666777888#10#4545344545#3344556677#";
  291. blevel[7] = "33#456456234567823456782345678456456#222333444444455555556666666777888#12#545634674565#344455556667#";
  292. blevel[8] = "33#456456234567823456782345678456456#222333444444455555556666666777888#14#54563572357828#23334445555566#";
  293. blevel[9] = "41#13579134567934567134567934567134567913579#11111333333344444555555566666777777799999#11#34344566767#33445556677#";
  294. blevel[10] = "33#456456234567823456782345678456456#222333444444455555556666666777888#16#4454564567456454#2334445555666778#";
  295. blevel[11] = "41#19245684562345678234567823456784562456819#11222223334444444555555566666667778888899#17#43478234567834784#34444555555566667#";
  296. blevel[12] = "45#128145689456234567823456782345678456124569289#111222222333444444455555556666666777888888999#21#463456723456783456746#334444455555556666677#";
  297. blevel[13] = "49#1289124568945623456782345678234567845612456891289#1111222222233344444445555555666666677788888889999#24#456456235734673578456456#222333444455556666777888#";
  298. blevel[14] = "45#128914569456234567823456782345678456145691289#111122222333444444455555556666666777888889999#24#545634567234678345674565#233344444555555666667778#";
  299. blevel[15] = "46#1934567345672345678234567823456783456783456719#1122222333334444444555555566666667777778888899#18#353562356734567467#223345566677777888#";
  300. blevel[16] = "45#137924568456234567823456782345678456245681379#111122222333444444455555556666666777888889999#18#523578234678235785#344444555555666667#";
  301. blevel[17] = "37#9245645623456782345678234567845645681#1222233344444445555555666666677788889#25#4564562378234567823784565#2223334444555555566667778#";
  302. blevel[18] = "47#12891456934567234567812346789235783467145691289#11112222233333444444455555555666667777888889999#12#651346793575#345555556668#";
  303. blevel[19] = "45#281245689456234567823456782345678456124568928#112222222333444444455555556666666777888888899#16#4564565475456456#2223334556777888#";
  304. blevel[20] = "45#128145689456234567823456782345678456124569289#111222222333444444455555556666666777888888999#26#45645623572345672357456456#22233344445555556666777888#";
  305. blevel[21] = "41#19245684562345678234567823456784562456819#11222223334444444555555566666667778888899#27#456456345678567825678456456#222333444444555566666777888#";
  306. blevel[22] = "45#128924568456234567823456782345678456245681289#111122222333444444455555556666666777888889999#16#5453782467378455#2334445555666778#";
  307. blevel[23] = "45#193572345678234567813456792345678234567835719#112223333333444444455555556666666777777788899#18#546734636734567345#233344455566666777#";
  308. blevel[24] = "41#19245684562345678234567823456784562456819#11222223334444444555555566666667778888899#32#45645623456782346782345678456456#22233344444445555556666666777888#";
  309. blevel[25] = "28#1233489345678934567893489123#2223333444444455555556666777#14#12495685684912#22334445556677#";
  310. blevel[26] = "45#281245689456234567823456782345678456124568928#112222222333444444455555556666666777888888899#32#45645623456782345782345678456456#22233344444445555556666666777888#";
  311. blevel[27] = "49#1289145693456723456782345678234567834567145691289#1111222223333344444445555555666666677777888889999#35#45635672345678234678234567834567456#22233334444444555555666666677777888#";
  312. blevel[28] = "37#1945645623456782345678234567845645619#1122233344444445555555666666677788899#32#45645623456782345678234567846456#22233344444445555555666666677888#";
  313. blevel[29] = "49#2345678234567823456782345678234567823456782345678#2222222333333344444445555555666666677777778888888#40#3456234567823456782346723572345678235678#2222333333344444445555566667777777888888#";
  314. blevel[30] = "41#19145694562345678234567823456784564561289#11222223334444444555555566666667778889999#32#46456234567823456782345678456456#22333444444455555556666666777888#";
  315. blevel[31] = "45#456456456123456789123456789123456789456456456#111222333444444444555555555666666666777888999#44#45645645612345678912345678912356789456456456#11122233344444444455555555566666666777888999#";
  316. blevel[32] = "37#1945645623456782345678234567845645619#1122233344444445555555666666677788899#32#45645623457823456782345678456456#22233344444455555556666666777888#";
  317. blevel[33] = "45#128945634567234567823456782345678345674561289#111122233333444444455555556666666777778889999#35#45634567234567823478234567834567456#22233333444444455555666666677777888#";
  318. blevel[34] = "49#1289124568945623456782345678234567845612456891289#1111222222233344444445555555666666677788888889999#32#45645623456782345678245678456456#22233344444445555555666666777888#";
  319. blevel[35] = "48#234678113456781345678345678134567813456781345678#111111233333334444444555555666666677777778888888#35#34567834567834578345678345678345678#33333344444455555666666777777888888#";
  320. blevel[36] = "45#191245689456234567823456782345678456124568919#112222222333444444455555556666666777888888899#32#45645623456723456782345678456456#22233344444455555556666666777888#";
  321. blevel[37] = "57#123489135678123456781234568134568356781234589234681234679#111111222222333333334444444555555666667777777888889999999#37#1241357813458123458346835678242348234#1112222233333444444555566666778888999#";
  322. blevel[38] = "49#1289124568945623456782345678234567845612456891289#1111222222233344444445555555666666677788888889999#31#4564562345678234567823456784545#2223334444444555555566666667788#";
  323. blevel[39] = "45#191456934567234567823456782345678345671456919#112222233333444444455555556666666777778888899#35#45634567234567823467823456783456745#22233333444444455555566666667777788#";
  324. blevel[40] = "41#12456894562345678234567823456784561245689#22222223334444444555555566666667778888888#31#4564562345672345672345678456456#2223334444445555556666666777888#";
  325. levels = blevel.length - 1;
  326. _parent.controls.levind = level + " of " + levels;
  327. j = 0;
  328. while(levels >= j)
  329. {
  330.    completedlevels[j] = 0;
  331.    j++;
  332. }
  333.