home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Classicos / SheepTeroids.swf / scripts / frame_28 / DoAction.as
Encoding:
Text File  |  2005-08-05  |  5.8 KB  |  272 lines

  1. function startLevel()
  2. {
  3.    ship.dx = 0;
  4.    ship.dy = 0;
  5.    bullets = new Array();
  6.    rocks = new Array();
  7.    level = 0;
  8.    i = 0;
  9.    while(i < gameLevel + 1)
  10.    {
  11.       newRock(100,0,0);
  12.       i++;
  13.    }
  14.    timeOfLastFire = 0;
  15.    score = 0;
  16. }
  17. function shipTurn(amt)
  18. {
  19.    ship._rotation += amt;
  20. }
  21. function shipThrust()
  22. {
  23.    ship.dx += Math.cos(6.283185307179586 * (ship._rotation - 90) / 360);
  24.    ship.dy += Math.sin(6.283185307179586 * (ship._rotation - 90) / 360);
  25.    if(ship.dy > 18)
  26.    {
  27.       ship.dy = 18;
  28.    }
  29.    if(ship.dx > 18)
  30.    {
  31.       ship.dx = 18;
  32.    }
  33.    if(ship.dy < -18)
  34.    {
  35.       ship.dy = -18;
  36.    }
  37.    if(ship.dx < -18)
  38.    {
  39.       ship.dx = -18;
  40.    }
  41.    ship.gotoAndPlay("thrust");
  42. }
  43. function shipBreak()
  44. {
  45.    ship.dx *= 0.5;
  46.    ship.dy *= 0.5;
  47. }
  48. function shipFire()
  49. {
  50.    if(timeOfLastFire + 200 < getTimer())
  51.    {
  52.       timeOfLastFire = getTimer();
  53.       level++;
  54.       attachMovie("bullet","bullet" + level,level);
  55.       clip = _root["bullet" + level];
  56.       clip._x = ship._x;
  57.       clip._y = ship._y;
  58.       clip.dx = 10 * Math.cos(6.283185307179586 * (ship._rotation - 90) / 360);
  59.       clip.dy = 10 * Math.sin(6.283185307179586 * (ship._rotation - 90) / 360);
  60.       bullets.push(clip);
  61.    }
  62. }
  63. function shipMove()
  64. {
  65.    ship._x += ship.dx;
  66.    if(ship._x > 550)
  67.    {
  68.       ship._x -= 550;
  69.    }
  70.    if(ship._x < 0)
  71.    {
  72.       ship._x += 550;
  73.    }
  74.    ship._y += ship.dy;
  75.    if(ship._y > 400)
  76.    {
  77.       ship._y -= 400;
  78.    }
  79.    if(ship._y < 0)
  80.    {
  81.       ship._y += 400;
  82.    }
  83. }
  84. function bulletsMove()
  85. {
  86.    i = bullets.length - 1;
  87.    while(i >= 0)
  88.    {
  89.       bullets[i]._x += bullets[i].dx;
  90.       bullets[i]._y += bullets[i].dy;
  91.       if(bullets[i]._x > 550 or bullets[i]._x < 0 or bullets[i]._y > 400 or bullets[i]._y < 0)
  92.       {
  93.          bullets[i].removeMovieClip();
  94.          bullets.splice(i,1);
  95.       }
  96.       i--;
  97.    }
  98. }
  99. function newRock(size, x, y)
  100. {
  101.    level++;
  102.    rockNum = int(Math.random() * 3 + 1);
  103.    attachMovie("rock" + rockNum,"rock" + level,level);
  104.    clip = _root["rock" + level];
  105.    clip._x = x;
  106.    clip._y = y;
  107.    clip._xscale = size;
  108.    clip._yscale = size;
  109.    clip.dx = Math.Random() * gameLevel + 0.5;
  110.    if(Math.random() < 0.5)
  111.    {
  112.       clip.dx *= -1;
  113.    }
  114.    clip.dy = Math.Random() * gameLevel + 0.5;
  115.    if(Math.random() < 0.5)
  116.    {
  117.       clip.dy *= -1;
  118.    }
  119.    clip.spin = Math.random() * 6 - 3;
  120.    rocks.push(clip);
  121. }
  122. function rocksMove()
  123. {
  124.    i = rocks.length - 1;
  125.    while(i >= 0)
  126.    {
  127.       clip = rocks[i].clip;
  128.       rocks[i]._x += rocks[i].dx;
  129.       if(rocks[i]._x > 550)
  130.       {
  131.          rocks[i]._x -= 550;
  132.       }
  133.       if(rocks[i]._x < 0)
  134.       {
  135.          rocks[i]._x += 550;
  136.       }
  137.       rocks[i]._y += rocks[i].dy;
  138.       if(rocks[i]._y > 400)
  139.       {
  140.          rocks[i]._y -= 400;
  141.       }
  142.       if(rocks[i]._y < 0)
  143.       {
  144.          rocks[i]._y += 400;
  145.       }
  146.       rocks[i]._rotation += rocks[i].spin;
  147.       i--;
  148.    }
  149. }
  150. function checkHits()
  151. {
  152.    i = rocks.length - 1;
  153.    while(i >= 0)
  154.    {
  155.       j = bullets.length - 1;
  156.       while(j >= 0)
  157.       {
  158.          if(rocks[i].hitTest(bullets[j]._x,bullets[j]._y,true))
  159.          {
  160.             if(rocks[1])
  161.             {
  162.                bleat.start();
  163.             }
  164.             else
  165.             {
  166.                bleat2.start();
  167.             }
  168.             bullets[j].removeMovieClip();
  169.             bullets.splice(j,1);
  170.             if(rocks[i]._xscale == 100)
  171.             {
  172.                if(multi50 == 0 && multi25 == 0)
  173.                {
  174.                   multi++;
  175.                }
  176.                else
  177.                {
  178.                   multi = 0;
  179.                }
  180.                multi50 = 0;
  181.                multi25 = 0;
  182.                multi100++;
  183.             }
  184.             else if(rocks[i]._xscale == 50)
  185.             {
  186.                if(multi100 == 0 && multi25 == 0)
  187.                {
  188.                   multi++;
  189.                }
  190.                else
  191.                {
  192.                   multi = 0;
  193.                }
  194.                multi100 = 0;
  195.                multi25 = 0;
  196.                multi50++;
  197.             }
  198.             else if(rocks[i]._xscale == 25)
  199.             {
  200.                if(multi50 == 0 && multi100 == 0)
  201.                {
  202.                   multi++;
  203.                }
  204.                else
  205.                {
  206.                   multi = 0;
  207.                }
  208.                multi50 = 0;
  209.                multi100 = 0;
  210.                multi25++;
  211.             }
  212.             if(multipause == false)
  213.             {
  214.                multilights.gotoAndPlay(multi + 1);
  215.             }
  216.             newsize = rocks[i]._xscale / 2;
  217.             x = rocks[i]._x;
  218.             y = rocks[i]._y;
  219.             rocks[i].removeMovieClip();
  220.             rocks.splice(i,1);
  221.             if(newsize >= 25)
  222.             {
  223.                newRock(newsize,x,y);
  224.                newRock(newsize,x,y);
  225.             }
  226.             score += 10;
  227.             break;
  228.          }
  229.          j--;
  230.       }
  231.       if(rocks[i].hitTest(ship._x + 8,ship._y + 8,true) || rocks[i].hitTest(ship._x - 8,ship._y + 8,true) || rocks[i].hitTest(ship._x + 8,ship._y - 8,true) || rocks[i].hitTest(ship._x - 8,ship._y - 8,true))
  232.       {
  233.          ship.gotoAndPlay("hit");
  234.       }
  235.       i--;
  236.    }
  237.    if(rocks.length == 0)
  238.    {
  239.       removeAll();
  240.       gotoAndPlay(38);
  241.       gameLevel++;
  242.    }
  243. }
  244. function removeAll()
  245. {
  246.    i = 0;
  247.    while(i < bullets.length)
  248.    {
  249.       bullets[i].removeMovieClip();
  250.       i++;
  251.    }
  252.    i = 0;
  253.    while(i < rocks.length)
  254.    {
  255.       rocks[i].removeMovieClip();
  256.       i++;
  257.    }
  258. }
  259. stop();
  260. _root.removeAll();
  261. multi = 0;
  262. multiplier = 1;
  263. multi100 = 0;
  264. multi50 = 0;
  265. multi25 = 0;
  266. multipause = false;
  267. livesclip.gotoAndStop(lives);
  268. bleat = new Sound();
  269. bleat.attachSound("bleat");
  270. bleat2 = new Sound();
  271. bleat2.attachSound("bleat2");
  272.