home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Nave / bermuda_triangle.swf / scripts / frame_20 / DoAction.as
Encoding:
Text File  |  2006-07-26  |  5.8 KB  |  232 lines

  1. function hit(rad1, rad2, dist)
  2. {
  3.    if(Math.abs(dist) < rad1 + rad2)
  4.    {
  5.       trace("rad1=" + rad1);
  6.       trace("rad2=" + rad2);
  7.       trace("dist=" + dist);
  8.    }
  9.    return Math.abs(dist) < rad1 + rad2;
  10. }
  11. onEnterFrame = function()
  12. {
  13.    movePlane();
  14.    handleVolume();
  15. };
  16. movePlane = function()
  17. {
  18.    if(!gameover)
  19.    {
  20.       if(!plane.hit)
  21.       {
  22.          time = int((getTimer() - startTime) / 100) / 10;
  23.          var my = _ymouse;
  24.          my = Math.min(my,325);
  25.          my = Math.max(my,30);
  26.          var fr = int(_ymouse / 15);
  27.          var goal = (my - plane._y) * 0.09;
  28.          plane.gotoAndStop(fr + 8);
  29.          plane._y += goal;
  30.          if(goal < 5)
  31.          {
  32.             plane._y += Math.sin(x) * 2;
  33.             x += 0.1;
  34.          }
  35.          else
  36.          {
  37.             x = 0;
  38.          }
  39.       }
  40.       else
  41.       {
  42.          goal = (500 - plane._y) * 0.03;
  43.          plane._y += goal;
  44.          if(plane._Y > 425)
  45.          {
  46.             doGameover();
  47.          }
  48.       }
  49.       plane._rotation = goal;
  50.       shadow._alpha = my / 4 * 0.3;
  51.       shadow._xscale = shadow._yscale = 100 + (400 - my) * 0.1;
  52.       shadow._x = plane._x + (400 - my) * 0.1;
  53.       ball0._y = plane._y;
  54.    }
  55. };
  56. reset = function()
  57. {
  58.    for(prop in _root.soundholder)
  59.    {
  60.       _root.soundholder[prop].soundname.stop();
  61.    }
  62.    soundHolder.theme.soundname.stop();
  63.    soundHolder.prop.soundname.stop();
  64.    _root.mainSound = new Sound(_root);
  65.    _root.mainSound.setVolume(100);
  66.    _global.soundCount = 1000000;
  67.    _global.vol = 100;
  68.    removeMovieClip(soundHolder);
  69.    createEmptyMovieClip("soundHolder",1000);
  70.    startTheme();
  71.    scores._visible = false;
  72.    _global.thememuted = false;
  73.    time = 0;
  74.    startTime = getTimer();
  75.    v = setInterval(thunder,10000);
  76.    v2 = setInterval(ufo,1000);
  77.    blocker.gotoAndStop(1);
  78.    ufocount = 0;
  79.    gameover = false;
  80.    soundHolder.prop.soundname.stop();
  81.    playSound("prop","prop",1000,0);
  82.    plane.hit = false;
  83.    plane._y = 200;
  84.    replay.gotoAndStop(1);
  85.    ocean.play();
  86.    rain.play();
  87. };
  88. handleScore = function()
  89. {
  90.    scores.scripting.test(time);
  91. };
  92. doGameover = function()
  93. {
  94.    stopTheme();
  95.    soundHolder.prop.soundname = null;
  96.    ocean.stop();
  97.    rain.stop();
  98.    clearInterval(v2);
  99.    clearInterval(v);
  100.    playSound("crash","crash",1,0);
  101.    playSound("splash","splash",1,0);
  102.    gameover = true;
  103.    var i = 1;
  104.    while(i < 2000)
  105.    {
  106.       removeMovieClip(eval("ball" + i));
  107.       removeMovieClip(eval("ufo" + i));
  108.       i++;
  109.    }
  110.    blocker.gotoAndPlay(2);
  111.    scores._visible = true;
  112. };
  113. playReset = function()
  114. {
  115.    replay.gotoAndPlay(2);
  116. };
  117. thunder = function()
  118. {
  119.    lightning.play();
  120.    playSound("storm","storm",1,0);
  121. };
  122. ufo = function()
  123. {
  124.    clearInterval(v2);
  125.    v2 = setInterval(ufo,1000 - ufocount * 2);
  126.    ufocount++;
  127.    attachMovie("ufo","ufo" + ufocount,10000 + ufocount);
  128.    attachMovie("ball","ball" + ufocount,12000 + ufocount);
  129.    var mc = eval("ufo" + ufocount);
  130.    var ball = eval("ball" + ufocount);
  131.    mc.ball = ball;
  132.    mc._x = 415 + random(50);
  133.    mc._y = random(300) + 50;
  134.    mc.speed = 14 + int(ufocount / 5) + random(6);
  135.    mc.scale = 100 - (400 - mc._y) * 0.1;
  136.    mc._xscale = mc._yscale = mc.scale;
  137.    mc.ball._xscale = mc.ball._yscale = mc.scale * 0.9;
  138.    mc.onEnterframe = function()
  139.    {
  140.       if(!gameover and mc.inPlace)
  141.       {
  142.          if(hit(ball0._width / 2,mc.ball._width / 2,distance(ball0._x,ball0._y,mc.ball._x,mc.ball._y)) and !plane.hit)
  143.          {
  144.             plane.hit = true;
  145.             plane.fire.play();
  146.             soundHolder.prop.soundname.stop();
  147.             playSound("zoop","zoop",1,0);
  148.             playSound("sputter","sputter",1,2.5);
  149.          }
  150.          mc.ball._y = mc._y;
  151.          mc.ball._x = mc._x - 11;
  152.          mc._x -= mc.speed;
  153.          if(mc._x < -150)
  154.          {
  155.             mc.onEnterframe = null;
  156.             removeMovieClip(mc);
  157.          }
  158.       }
  159.    };
  160. };
  161. distance = function(x1, y1, x2, y2)
  162. {
  163.    return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
  164. };
  165. removeMovieClip(soundHolder);
  166. createEmptyMovieClip("soundHolder",1000);
  167. _global.playSound = function(targetSound, soundnameclip, loops, offset)
  168. {
  169.    removeMovieClip(targetSound);
  170.    _root.soundHolder.createEmptyMovieClip(targetSound,1000 + _global.soundCount);
  171.    for(prop in _root.soundholder)
  172.    {
  173.       if(typeof _root.soundholder[prop] == "movieclip")
  174.       {
  175.          if(_root.soundholder[prop].soundname == undefined)
  176.          {
  177.             _root.soundholder[prop].soundname = new Sound(soundholder[prop]);
  178.             _root.soundholder[prop].soundname.attachSound(targetSound);
  179.             _root.soundholder[prop].soundname.start(offset,loops);
  180.          }
  181.       }
  182.    }
  183. };
  184. _global.handleVolume = function()
  185. {
  186.    soundHolder.onEnterFrame = function()
  187.    {
  188.       var inc = 7.5;
  189.       if(_global.muted)
  190.       {
  191.          dir = - inc;
  192.       }
  193.       else
  194.       {
  195.          dir = inc;
  196.       }
  197.       _global.vol += dir;
  198.       _global.vol = Math.max(_global.vol,0);
  199.       _global.vol = Math.min(_global.vol,100);
  200.       _root.mainSound.setVolume(_global.vol);
  201.       if(thememuted)
  202.       {
  203.          themedir -= inc;
  204.       }
  205.       else
  206.       {
  207.          themedir += inc;
  208.       }
  209.       themedir = Math.max(themedir,0);
  210.       themedir = Math.min(themedir,100);
  211.       soundHolder.theme.soundname.setVolume(themedir);
  212.    };
  213. };
  214. handleVolume();
  215. _global.startTheme = function()
  216. {
  217.    soundHolder.createEmptyMovieClip("theme",1000);
  218.    soundHolder.theme.soundname = new Sound(soundHolder);
  219.    soundHolder.theme.soundname.attachSound("theme");
  220.    soundHolder.theme.soundname.setVolume(0);
  221.    soundHolder.theme.soundname.start(0,1000);
  222. };
  223. _global.stopTheme = function()
  224. {
  225.    _global.thememuted = true;
  226. };
  227. _global.unMute = function()
  228. {
  229.    _global.muted = false;
  230. };
  231. reset();
  232.