home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / time-travel.swf / scripts / frame_9 / DoAction.as
Encoding:
Text File  |  2005-09-29  |  11.6 KB  |  550 lines

  1. function initGame()
  2. {
  3.    nextBulletTime = 0;
  4.    nextBullet = 0;
  5.    bullets = [];
  6.    score = 0;
  7.    level = 1;
  8.    px = 10;
  9.    px2 = 10;
  10.    speedx = 3;
  11.    speedy = 3;
  12.    numdeballs = 0;
  13.    currentballs = numdeballs;
  14.    speedbat = 5;
  15.    _root.medidor._x = 19;
  16.    _root.medidor._y = 12;
  17.    vida = 19;
  18.    _root.attachMovie("rayo","proyectil",numdeballs + 100);
  19.    _root.proyectil._x = 0;
  20.    _root.proyectil._y = -10;
  21.    lastlevel = 15;
  22. }
  23. function startTimer()
  24. {
  25.    levelTime = getTimer();
  26.    batTime = levelTime + 30000;
  27. }
  28. function extralife()
  29. {
  30.    _root.attachMovie("bat","xtralife",1000);
  31.    _root.xtralife._x = -20;
  32.    _root.xtralife._y = 50 + int(Math.random() * 15);
  33. }
  34. function moveXtraLife()
  35. {
  36.    _root.xtralife._x += speedbat;
  37.    if(420 < _root.xtralife._x)
  38.    {
  39.       bat = 0;
  40.       _root.xtralife.removeMovieClip();
  41.    }
  42. }
  43. function checkXtraLife()
  44. {
  45.    levelTime = getTimer();
  46.    if(batTime < levelTime)
  47.    {
  48.       extralife();
  49.       bat = 1;
  50.       startTimer();
  51.    }
  52.    if(bat == 1)
  53.    {
  54.       moveXtraLife();
  55.    }
  56. }
  57. function newballs()
  58. {
  59.    startTimer();
  60.    i = 0;
  61.    while(i < numdeballs)
  62.    {
  63.       attachMovie("bola","reloj" + i,i);
  64.       _root["reloj" + i].watch.gotoAndPlay(framewatch);
  65.       _root["reloj" + i]._x = 20 + int(Math.random() * 300);
  66.       _root["reloj" + i]._y = 47 + int(Math.random() * 60);
  67.       valor = int(Math.random() * 2);
  68.       if(valor == 0)
  69.       {
  70.          _root["reloj" + i].dx = - (speedx + int(Math.random() * 5));
  71.       }
  72.       else
  73.       {
  74.          _root["reloj" + i].dx = speedx + int(Math.random() * 5);
  75.       }
  76.       _root["reloj" + i].dy = speedy + int(Math.random() * speedy);
  77.       _root["reloj" + i].tamano = 3;
  78.       i++;
  79.    }
  80. }
  81. function termino()
  82. {
  83.    if(currentballs == 0)
  84.    {
  85.       _root.pepe._y = -10;
  86.       _root.pepe._x = 150;
  87.       bat = 0;
  88.       _root.xtralife.removeMovieClip();
  89.       pausa();
  90.    }
  91. }
  92. function pausa()
  93. {
  94.    contador++;
  95.    if(5 < contador)
  96.    {
  97.       cambiarfondo();
  98.       nivel = "LEVEL " + level;
  99.    }
  100.    if(40 < contador)
  101.    {
  102.       nivel = " ";
  103.    }
  104.    if(50 < contador)
  105.    {
  106.       _root.pepe._y = 293;
  107.       newlevel2();
  108.    }
  109. }
  110. function cambiarfondo()
  111. {
  112.    if(7 >= level)
  113.    {
  114.       _root.fondo.gotoAndPlay("fondo" + level);
  115.    }
  116.    else
  117.    {
  118.       fondillo = level - 7;
  119.       _root.fondo.gotoAndPlay("fondo" + fondillo);
  120.    }
  121. }
  122. function newlevel2()
  123. {
  124.    if(level == 1)
  125.    {
  126.       framewatch = 2;
  127.       speedbat = 5;
  128.       speedy = 4;
  129.       contador = 0;
  130.       numdeballs = 1;
  131.       currentballs = 1;
  132.       newballs();
  133.    }
  134.    if(level == 2)
  135.    {
  136.       framewatch = 2;
  137.       speedbat = 6;
  138.       speedy = 4;
  139.       contador = 0;
  140.       numdeballs = 2;
  141.       currentballs = 2;
  142.       newballs();
  143.    }
  144.    if(level == 3)
  145.    {
  146.       framewatch = 2;
  147.       speedbat = 6;
  148.       speedy = 4;
  149.       contador = 0;
  150.       numdeballs = 3;
  151.       currentballs = 3;
  152.       newballs();
  153.    }
  154.    if(level == 4)
  155.    {
  156.       framewatch = 1;
  157.       speedbat = 7;
  158.       speedy = 6;
  159.       contador = 0;
  160.       numdeballs = 1;
  161.       currentballs = 1;
  162.       newballs();
  163.    }
  164.    if(level == 5)
  165.    {
  166.       framewatch = 1;
  167.       speedbat = 9;
  168.       speedy = 7;
  169.       contador = 0;
  170.       numdeballs = 2;
  171.       currentballs = 2;
  172.       newballs();
  173.    }
  174.    if(level == 6)
  175.    {
  176.       framewatch = 3;
  177.       speedbat = 8;
  178.       speedy = 7;
  179.       contador = 0;
  180.       numdeballs = 3;
  181.       currentballs = 3;
  182.       newballs();
  183.    }
  184.    if(level == 7)
  185.    {
  186.       framewatch = 3;
  187.       speedbat = 8;
  188.       speedy = 7;
  189.       contador = 0;
  190.       numdeballs = 4;
  191.       currentballs = 4;
  192.       newballs();
  193.    }
  194.    if(level == 8)
  195.    {
  196.       framewatch = 2;
  197.       speedbat = 9;
  198.       speedy = 7;
  199.       contador = 0;
  200.       numdeballs = 1;
  201.       currentballs = 1;
  202.       newballs();
  203.    }
  204.    if(level == 9)
  205.    {
  206.       framewatch = 2;
  207.       speedbat = 9;
  208.       speedy = 8;
  209.       contador = 0;
  210.       numdeballs = 2;
  211.       currentballs = 2;
  212.       newballs();
  213.    }
  214.    if(level == 10)
  215.    {
  216.       framewatch = 2;
  217.       speedbat = 9;
  218.       speedy = 8;
  219.       contador = 0;
  220.       numdeballs = 3;
  221.       currentballs = 3;
  222.       newballs();
  223.    }
  224.    if(level == 11)
  225.    {
  226.       framewatch = 1;
  227.       speedbat = 6;
  228.       speedy = 9;
  229.       contador = 0;
  230.       numdeballs = 1;
  231.       currentballs = 1;
  232.       newballs();
  233.    }
  234.    if(level == 12)
  235.    {
  236.       framewatch = 1;
  237.       speedbat = 7;
  238.       speedy = 8;
  239.       contador = 0;
  240.       numdeballs = 2;
  241.       currentballs = 2;
  242.       newballs();
  243.    }
  244.    if(level == 13)
  245.    {
  246.       framewatch = 3;
  247.       speedbat = 7;
  248.       speedy = 8;
  249.       contador = 0;
  250.       numdeballs = 3;
  251.       currentballs = 3;
  252.       newballs();
  253.    }
  254.    if(level == 14)
  255.    {
  256.       framewatch = 3;
  257.       speedbat = 8;
  258.       speedy = 8;
  259.       contador = 0;
  260.       numdeballs = 5;
  261.       currentballs = 5;
  262.       newballs();
  263.    }
  264. }
  265. function explodeball()
  266. {
  267.    boomsound();
  268.    attachMovie("bola","reloj" + numdeballs,numdeballs);
  269.    _root["reloj" + numdeballs].watch.gotoAndPlay(framewatch);
  270.    currentballs += 1;
  271.    _root["reloj" + numdeballs].gotoAndPlay("split");
  272.    _root["reloj" + numdeballs].tamano = _root["reloj" + pelotasacada].tamano;
  273.    _root["reloj" + numdeballs]._xscale = _root["reloj" + pelotasacada]._xscale;
  274.    _root["reloj" + numdeballs]._yscale = _root["reloj" + pelotasacada]._yscale;
  275.    _root["reloj" + numdeballs]._x = _root["reloj" + pelotasacada]._x + 20;
  276.    _root["reloj" + numdeballs]._y = _root["reloj" + pelotasacada]._y + 20;
  277.    _root["reloj" + pelotasacada].dy = - Math.abs(_root["reloj" + pelotasacada].dy);
  278.    _root["reloj" + numdeballs].dy = - Math.abs(_root["reloj" + pelotasacada].dy);
  279.    _root["reloj" + numdeballs].dx = - _root["reloj" + pelotasacada].dx;
  280.    numdeballs += 1;
  281. }
  282. function moveClocks()
  283. {
  284.    i = 0;
  285.    while(i < numdeballs)
  286.    {
  287.       _root["reloj" + i]._x += _root["reloj" + i].dx;
  288.       _root["reloj" + i]._y += _root["reloj" + i].dy;
  289.       diametro = _root["reloj" + i]._height / 2;
  290.       diametro2 = _root["reloj" + i]._width / 2;
  291.       if(380 < _root["reloj" + i]._x + diametro2)
  292.       {
  293.          _root["reloj" + i].dx = - _root["reloj" + i].dx;
  294.          _root["reloj" + i]._x -= diametro / 2;
  295.       }
  296.       if(_root["reloj" + i]._x < 20)
  297.       {
  298.          _root["reloj" + i].dx = - _root["reloj" + i].dx;
  299.       }
  300.       if(300 < _root["reloj" + i]._y)
  301.       {
  302.          _root["reloj" + i].dy = - _root["reloj" + i].dy;
  303.       }
  304.       if(_root["reloj" + i]._y - diametro < 37)
  305.       {
  306.          _root["reloj" + i].dy = - _root["reloj" + i].dy;
  307.          _root["reloj" + i]._y += diametro / 2;
  308.       }
  309.       i++;
  310.    }
  311. }
  312. function boomsound()
  313. {
  314.    s = new Sound();
  315.    s.attachSound("boom");
  316.    s.start();
  317. }
  318. function lasersound()
  319. {
  320.    if(currentballs != 0)
  321.    {
  322.       s = new Sound();
  323.       s.attachSound("laser");
  324.       s.start();
  325.    }
  326. }
  327. function electricsound()
  328. {
  329.    s = new Sound();
  330.    s.attachSound("electricity");
  331.    s.start();
  332. }
  333. function batsound()
  334. {
  335.    s = new Sound();
  336.    s.attachSound("batpoom");
  337.    s.start();
  338. }
  339. function hayContacto()
  340. {
  341.    if(_root["reloj" + pelotasacada].tamano == 1)
  342.    {
  343.       _root["reloj" + pelotasacada].gotoAndPlay("split2");
  344.       score += 50;
  345.       currentballs--;
  346.       boomsound();
  347.       if(currentballs == 0)
  348.       {
  349.          level++;
  350.          if(level == lastlevel)
  351.          {
  352.             endgame();
  353.          }
  354.       }
  355.    }
  356.    if(_root["reloj" + pelotasacada].tamano == 2)
  357.    {
  358.       _root["reloj" + pelotasacada].gotoAndPlay("split");
  359.       _root["reloj" + pelotasacada].tamano = 1;
  360.       _root["reloj" + pelotasacada]._xscale = 50;
  361.       _root["reloj" + pelotasacada]._yscale = 50;
  362.       score += 75;
  363.       explodeball();
  364.    }
  365.    if(_root["reloj" + pelotasacada].tamano == 3)
  366.    {
  367.       _root["reloj" + pelotasacada].gotoAndPlay("split");
  368.       _root["reloj" + pelotasacada].tamano = 2;
  369.       _root["reloj" + pelotasacada]._xscale = 75;
  370.       _root["reloj" + pelotasacada]._yscale = 75;
  371.       score += 100;
  372.       explodeball();
  373.    }
  374. }
  375. function dispara()
  376. {
  377.    if(nextBulletTime < getTimer())
  378.    {
  379.       lasersound();
  380.       protagonista.gotoAndPlay("fire2");
  381.       _root.attachMovie("rayo","proyectil" + nextBullet,nextBullet + 100);
  382.       if(px2 == 10)
  383.       {
  384.          _root["proyectil" + nextBullet]._x = _root.pepe._x + 12;
  385.          _root["proyectil" + nextBullet]._y = _root.pepe._y - 35;
  386.          _root["proyectil" + nextBullet]._xscale = 15;
  387.          _root["proyectil" + nextBullet]._yscale = 30;
  388.       }
  389.       else if(px2 == -10)
  390.       {
  391.          _root["proyectil" + nextBullet]._x = _root.pepe._x - 12;
  392.          _root["proyectil" + nextBullet]._y = _root.pepe._y - 35;
  393.          _root["proyectil" + nextBullet]._xscale = 15;
  394.          _root["proyectil" + nextBullet]._yscale = 30;
  395.       }
  396.       bullets.push(nextBullet);
  397.       nextBullet++;
  398.       nextBulletTime = getTimer() + 500;
  399.    }
  400. }
  401. function mueveProyectil()
  402. {
  403.    i = bullets.length - 1;
  404.    while(i >= 0)
  405.    {
  406.       bullet = _root["proyectil" + bullets[i]];
  407.       bullet._y -= 15;
  408.       if(bullet._y < 45)
  409.       {
  410.          bullet.removeMovieClip();
  411.          bullets.splice(i,1);
  412.       }
  413.       else if(chequeaChoque(bullet))
  414.       {
  415.          bullet.removeMovieClip();
  416.          bullets.splice(i,1);
  417.       }
  418.       i--;
  419.    }
  420. }
  421. function chequeaChoque(bullet)
  422. {
  423.    if(bat == 1)
  424.    {
  425.       d = _root.xtralife;
  426.       if(d.hitTest(bullet))
  427.       {
  428.          batsound();
  429.          score += 99;
  430.          vida = 19;
  431.          showvida();
  432.          d.removeMovieClip();
  433.          bat = 0;
  434.       }
  435.    }
  436.    it = 0;
  437.    while(it < numdeballs)
  438.    {
  439.       a = _root["reloj" + it];
  440.       if(a.hitTest(bullet))
  441.       {
  442.          pelotasacada = it;
  443.          hayContacto();
  444.          return true;
  445.       }
  446.       it++;
  447.    }
  448.    return false;
  449. }
  450. function muevePepe()
  451. {
  452.    protagonista = _root.pepe;
  453.    if(Key.isDown(Key.LEFT))
  454.    {
  455.       px = -10;
  456.       protagonista._xscale = - Math.abs(protagonista._xscale);
  457.       px2 = px;
  458.    }
  459.    else if(Key.isDown(Key.RIGHT))
  460.    {
  461.       px = 10;
  462.       px2 = px;
  463.       protagonista._xscale = Math.abs(protagonista._xscale);
  464.    }
  465.    else
  466.    {
  467.       px = 0;
  468.    }
  469.    protagonista._x += px;
  470.    if(px == 0 and protagonista._currentFrame != 1)
  471.    {
  472.       protagonista.gotoAndPlay("fire");
  473.    }
  474.    else if(px != 0 and protagonista._currentFrame == 1)
  475.    {
  476.       protagonista.gotoAndPlay("left");
  477.    }
  478.    if(protagonista._x >= 350)
  479.    {
  480.       protagonista._x = 350;
  481.    }
  482.    if(30 >= protagonista._x)
  483.    {
  484.       protagonista._x = 30;
  485.    }
  486.    if(Key.isDown(Key.SPACE))
  487.    {
  488.       _root.dispara();
  489.    }
  490. }
  491. function showvida()
  492. {
  493.    if(100 < vida)
  494.    {
  495.       endgame();
  496.       vida = 19;
  497.    }
  498.    _root.medidor._x = vida;
  499. }
  500. function endgame()
  501. {
  502.    it = 0;
  503.    while(it < numdeballs)
  504.    {
  505.       a = _root["reloj" + it];
  506.       a.removeMovieClip();
  507.       it++;
  508.    }
  509.    i = bullets.length - 1;
  510.    while(i >= 0)
  511.    {
  512.       bullet = _root["proyectil" + bullets[i]];
  513.       bullet.removeMovieClip();
  514.       i--;
  515.    }
  516.    if(level == lastlevel)
  517.    {
  518.       gotoAndPlay(12);
  519.    }
  520.    else
  521.    {
  522.       gotoAndPlay(11);
  523.    }
  524. }
  525. function TuddHurt()
  526. {
  527.    prot = _root.pepe;
  528.    it = 0;
  529.    while(it < numdeballs)
  530.    {
  531.       a = _root["reloj" + it];
  532.       if(distance(_root.pepe,_root["reloj" + it]) < 35)
  533.       {
  534.          electricsound();
  535.          vida += 2;
  536.          showvida();
  537.          prot.gotoAndPlay("humo");
  538.       }
  539.       it++;
  540.    }
  541. }
  542. function distance(clip1, clip2)
  543. {
  544.    tx = clip1._x - clip2._x;
  545.    ty = clip1._y - clip2._y;
  546.    return Math.sqrt(tx * tx + ty * ty);
  547. }
  548. Mouse.hide();
  549. stop();
  550.