home *** CD-ROM | disk | FTP | other *** search
/ PCNet 2003 October / PCNET_CD_2003_10_1.iso / surpriz / bubblewrap.swf / scripts / frame_1 / DoAction.as
Encoding:
Text File  |  2003-08-19  |  7.4 KB  |  310 lines

  1. function Pop()
  2. {
  3. }
  4. function resetStats()
  5. {
  6.    numpoppable = numpopped = nummanic = 0;
  7. }
  8. function setBubbleSize(newsize)
  9. {
  10.    bubblesize = newsize;
  11.    btnBSButton.instance5.gotoAndPlay(1);
  12. }
  13. function removeBubbles()
  14. {
  15.    for(bubble in sheet)
  16.    {
  17.       if(typeof sheet[bubble] == "movieclip")
  18.       {
  19.          sheet[bubble].removeMovieClip();
  20.       }
  21.    }
  22. }
  23. function makeBubbles()
  24. {
  25.    if(bubblesmade != bubblesize)
  26.    {
  27.       removeBubbles();
  28.       resetStats();
  29.       xPitch = bubblesize + 0.06451612903225806 * bubblesize;
  30.       yPitch = bubblesize - 0.06896551724137931 * bubblesize;
  31.       bubbleCols = Math.round(sheet._width / xPitch) + 1;
  32.       bubbleRows = Math.round(sheet._height / yPitch) + 1;
  33.       var col = 0;
  34.       while(col < bubbleCols)
  35.       {
  36.          var row = 0;
  37.          while(row < bubbleRows)
  38.          {
  39.             var x = col * xPitch + startx;
  40.             if(row % 2 != 0)
  41.             {
  42.                x += xPitch / 2;
  43.             }
  44.             var y = row * yPitch + starty;
  45.             sheet.attachMovie("Pop","pr" + row + "c" + col,bubbleCols * row + col,{_x:x,_y:y,_xscale:100 * (bubblesize / 31),_yscale:100 * (bubblesize / 31),r:row,c:col});
  46.             newBubble = sheet["pr" + row + "c" + col];
  47.             var bounds = newBubble.getBounds(_root);
  48.             if(bounds.xMax > sheetmask._width || bounds.xMin < 0 || bounds.yMax > sheetmask._height || bounds.yMin < 0)
  49.             {
  50.                newBubble.poppable = false;
  51.             }
  52.             row++;
  53.          }
  54.          col++;
  55.       }
  56.       bubblesmade = bubblesize;
  57.    }
  58.    else
  59.    {
  60.       resetSheet();
  61.    }
  62. }
  63. function enableSheet(enable)
  64. {
  65.    if(enable)
  66.    {
  67.       onpress = Pop.prototype.onPress;
  68.    }
  69.    else
  70.    {
  71.       onpress = null;
  72.    }
  73.    var col = 0;
  74.    while(col < bubbleCols)
  75.    {
  76.       var row = 0;
  77.       while(row < bubbleRows)
  78.       {
  79.          sheet["pr" + row + "c" + col].onPress = onpress;
  80.          sheet["pr" + row + "c" + col].useHandCursor = enable;
  81.          row++;
  82.       }
  83.       col++;
  84.    }
  85. }
  86. function resetSheet()
  87. {
  88.    resetStats();
  89.    for(bubble in sheet)
  90.    {
  91.       if(typeof sheet[bubble] == "movieclip")
  92.       {
  93.          sheet[bubble].onLoad();
  94.       }
  95.    }
  96. }
  97. function restartTimer()
  98. {
  99.    minutes = "00";
  100.    seconds = "00";
  101.    tenths = "0";
  102.    buttonPressTime = getTimer() / 1000 - pauseLength;
  103.    pause();
  104. }
  105. function pause()
  106. {
  107.    pauseTime = getTimer() / 1000;
  108.    timing = false;
  109.    txtMin.setTextFormat(timerOff);
  110.    txtColon.setTextFormat(timerOff);
  111.    txtSec.setTextFormat(timerOff);
  112.    txtDot.setTextFormat(timerOff);
  113.    txtTen.setTextFormat(timerOff);
  114. }
  115. function unpause()
  116. {
  117.    unpauseTime = getTimer() / 1000;
  118.    pauseLength = unpauseTime - pauseTime + pauseLength;
  119.    timing = true;
  120.    txtMin.setNewTextFormat(timerOn);
  121.    txtColon.setNewTextFormat(timerOn);
  122.    txtSec.setNewTextFormat(timerOn);
  123.    txtDot.setNewTextFormat(timerOn);
  124.    txtTen.setNewTextFormat(timerOn);
  125.    txtMin.setTextFormat(timerOn);
  126.    txtColon.setTextFormat(timerOn);
  127.    txtSec.setTextFormat(timerOn);
  128.    txtDot.setTextFormat(timerOn);
  129.    txtTen.setTextFormat(timerOn);
  130. }
  131. Math.randomBetween = function(a, b)
  132. {
  133.    return a + Math.floor(Math.random() * (b - a + 1));
  134. };
  135. Pop.prototype = new MovieClip();
  136. Pop.prototype.onLoad = function()
  137. {
  138.    if(this.poppable)
  139.    {
  140.       if(Math.randomBetween(1,250) == 1)
  141.       {
  142.          buddycase = Math.randomBetween(1,3);
  143.          switch(buddycase)
  144.          {
  145.             case 1:
  146.                buddyc = this.c - 1;
  147.                buddyr = this.r;
  148.                break;
  149.             case 2:
  150.                buddyc = this.c;
  151.                buddyr = this.r - 1;
  152.                if(this.r % 2 == 0)
  153.                {
  154.                   buddyc--;
  155.                }
  156.                break;
  157.             case 3:
  158.                buddyc = this.c + 1;
  159.                buddyr = this.r - 1;
  160.                if(this.r % 2 == 0)
  161.                {
  162.                   buddyc--;
  163.                   break;
  164.                }
  165.          }
  166.          if(sheet["pr" + buddyr + "c" + buddyc].poppable)
  167.          {
  168.             this.buddy = "pr" + buddyr + "c" + buddyc;
  169.             sheet["pr" + buddyr + "c" + buddyc].buddy = "pr" + this.r + "c" + this.c;
  170.          }
  171.       }
  172.       else
  173.       {
  174.          this.buddy = null;
  175.       }
  176.       this.gotoAndStop(Math.randombetween(1,6));
  177.       numpoppable++;
  178.    }
  179.    else
  180.    {
  181.       this.gotoAndStop(Math.randombetween(10,15));
  182.    }
  183. };
  184. Pop.prototype.onPress = function(manic)
  185. {
  186.    if(this._currentframe < 10)
  187.    {
  188.       this.gotoAndStop(Math.randomBetween(10,15));
  189.       specialrandom = Math.randomBetween(1,2000);
  190.       if(this.buddy != null && !Key.isDown(66) && sheet[this.buddy]._currentFrame >= 10)
  191.       {
  192.          sheet[this.buddy].gotoAndStop(Math.randomBetween(1,6));
  193.          buddysound.start();
  194.          numpopped--;
  195.          if(manic)
  196.          {
  197.             nummanic--;
  198.          }
  199.       }
  200.       else if(specialrandom < 5 && !manic)
  201.       {
  202.          specialsound[specialrandom].start();
  203.       }
  204.       else if(specialrandom == 5)
  205.       {
  206.          fartx = this._x;
  207.          farty = this._y;
  208.          fartinst = "inst" + fartx + farty;
  209.          sheet.attachMovie("fart",fartinst,numpoppable * 2,{_x:fartx,_y:farty});
  210.       }
  211.       else
  212.       {
  213.          popsound[Math.randomBetween(1,9)].start();
  214.       }
  215.       numpopped++;
  216.       if(numpopped == 1)
  217.       {
  218.          unpause();
  219.       }
  220.       if(manic)
  221.       {
  222.          nummanic++;
  223.       }
  224.       if(numpopped == numpoppable)
  225.       {
  226.          pause();
  227.          _root.play();
  228.       }
  229.    }
  230. };
  231. Pop.prototype.onRollOver = function()
  232. {
  233.    if(Key.isDown(16) || chkManic.getValue())
  234.    {
  235.       this.onPress(true);
  236.    }
  237. };
  238. Pop.prototype.poppable = true;
  239. Pop.prototype.buddy = null;
  240. Pop.prototype.r = Pop.prototype.c = 0;
  241. Object.registerClass("Pop",Pop);
  242. var startx = 2;
  243. var starty = 2;
  244. timerOn = new TextFormat();
  245. timerOff = new TextFormat();
  246. timerOn.color = 34816;
  247. timerOff.color = 16711680;
  248. _root.onLoad = function()
  249. {
  250.    presetsmall = 20;
  251.    presetmedium = 31;
  252.    presetlarge = 49;
  253.    setBubbleSize(presetmedium);
  254.    makeBubbles();
  255. };
  256. popsound = new Array();
  257. var n = 1;
  258. while(n < 10)
  259. {
  260.    popsound[n] = new Sound();
  261.    popsound[n].attachSound("bw-pop" + n);
  262.    n++;
  263. }
  264. specialsound = new Array();
  265. var n = 1;
  266. while(n < 5)
  267. {
  268.    specialsound[n] = new Sound();
  269.    n++;
  270. }
  271. specialsound[1].attachSound("aroogalong");
  272. specialsound[2].attachSound("flush3");
  273. specialsound[3].attachSound("splash");
  274. specialsound[4].attachSound("splat");
  275. buddysound = new Sound();
  276. buddysound.attachSound("buddyswap");
  277. _root.onEnterFrame = function()
  278. {
  279.    totalTime = getTimer() / 1000 - pauseLength;
  280.    goTime = totalTime - buttonPressTime;
  281.    if(timing)
  282.    {
  283.       hours = Math.floor(goTime / 3600);
  284.       minutes = Math.floor((goTime / 3600 - hours) * 60);
  285.       seconds = Math.floor(((goTime / 3600 - hours) * 60 - minutes) * 60);
  286.       tenths = Math.floor((gotime - (seconds + minutes * 60 + hours * 3600)) * 10);
  287.       minutes += hours * 60;
  288.       if(seconds < 10)
  289.       {
  290.          seconds = "0" + seconds;
  291.       }
  292.       if(minutes < 10)
  293.       {
  294.          minutes = "0" + minutes;
  295.       }
  296.       if(minutes == "99")
  297.       {
  298.          if(seconds == "59")
  299.          {
  300.             if(tenths = "9")
  301.             {
  302.                pause();
  303.                _root.play();
  304.             }
  305.          }
  306.       }
  307.    }
  308. };
  309. stop();
  310.