home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / Moss_2_mochiads.swf / scripts / frame_4 / DoAction.as
Encoding:
Text File  |  2008-09-02  |  16.4 KB  |  743 lines

  1. function checkState()
  2. {
  3.    sound.setPan(Math.round((player._x - 250) * 0.4) / 4);
  4.    if(State == "falling")
  5.    {
  6.       if(ground.hitTest(player._x,player.getBounds(_root).yMax + 2,true))
  7.       {
  8.          fixPosition();
  9.          State = "standing";
  10.          player._y += 1;
  11.          djump = "fresh";
  12.          yforce = 0;
  13.       }
  14.       else if(ground.hitTest(player.getBounds(_root).xMin - 1,player._y,true) && Left && !ground.hitTest(player._x,player.getBounds(_root).yMax + 3,true) && player._y > 0)
  15.       {
  16.          State = "hanging";
  17.          djump = "used";
  18.       }
  19.       else if(ground.hitTest(player.getBounds(_root).xMax + 1,player._y,true) && Right && !ground.hitTest(player._x,player.getBounds(_root).yMax + 3,true) && player._y > 0)
  20.       {
  21.          State = "hanging";
  22.          djump = "used";
  23.       }
  24.       else
  25.       {
  26.          fall();
  27.          applySpeed();
  28.          fallHit();
  29.       }
  30.    }
  31.    else if(State == "hanging")
  32.    {
  33.       fixPosition();
  34.       getKeys();
  35.       if(ground.hitTest(player.getBounds(_root).xMax + 4,player._y,true) && !Right && !Up)
  36.       {
  37.          State = "falling";
  38.          player._x--;
  39.          yforce = 0;
  40.       }
  41.       else if(ground.hitTest(player.getBounds(_root).xMin - 4,player._y,true) && !Left && !Up)
  42.       {
  43.          State = "falling";
  44.          player._x = player._x + 1;
  45.          yforce = 0;
  46.       }
  47.       else if(ground.hitTest(player.getBounds(_root).xMax + 4,player._y,true) && (!Right && Up))
  48.       {
  49.          fixPosition();
  50.          State = "jumping";
  51.          yforce = -10;
  52.          xforce = -5;
  53.       }
  54.       else if(ground.hitTest(player.getBounds(_root).xMin - 4,player._y,true) && (!Left && Up))
  55.       {
  56.          State = "jumping";
  57.          yforce = -10;
  58.          xforce = 5;
  59.       }
  60.       else if(!Left && !Right && !Up)
  61.       {
  62.          State = "falling";
  63.          trace("NOT USED");
  64.       }
  65.       else
  66.       {
  67.          hangHit();
  68.          checkSide();
  69.       }
  70.    }
  71.    else if(State == "jumping")
  72.    {
  73.       if(yforce >= 0)
  74.       {
  75.          State = "falling";
  76.       }
  77.       else if(ground.hitTest(player.getBounds(_root).xMin - 1,player._y,true) && Left && !ground.hitTest(player._x,player.getBounds(_root).yMax + 3,true) && player._y > 0)
  78.       {
  79.          State = "hanging";
  80.       }
  81.       else if(ground.hitTest(player.getBounds(_root).xMax + 1,player._y,true) && Right && !ground.hitTest(player._x,player.getBounds(_root).yMax + 3,true) && player._y > 0)
  82.       {
  83.          State = "hanging";
  84.       }
  85.       else
  86.       {
  87.          jump();
  88.          applySpeed();
  89.          jumpHit();
  90.       }
  91.    }
  92.    else if(State == "standing")
  93.    {
  94.       fixPosition();
  95.       if(!ground.hitTest(player._x,player.getBounds(_root).yMax + 1,true))
  96.       {
  97.          State = "falling";
  98.       }
  99.       else if(Up)
  100.       {
  101.          State = "jumping";
  102.          player._y -= 1;
  103.          yforce = -10;
  104.       }
  105.       else
  106.       {
  107.          stand();
  108.          applySpeed();
  109.          standHit();
  110.       }
  111.    }
  112. }
  113. function fall()
  114. {
  115.    yforce++;
  116.    run(0.5);
  117.    if(yforce <= 5 && Up && djump == "fresh")
  118.    {
  119.       yforce = -7;
  120.       djump = "used";
  121.    }
  122. }
  123. function hang()
  124. {
  125. }
  126. function jump()
  127. {
  128.    yforce++;
  129.    run(0.5);
  130. }
  131. function stand()
  132. {
  133.    run(1);
  134. }
  135. function applySpeed()
  136. {
  137.    player._x += xforce;
  138.    player._y += yforce;
  139. }
  140. function fallHit()
  141. {
  142.    while(ground.hitTest(player.getBounds(_root).xMin,player._y,true) && !ground.hitTest(player.getBounds(_root).xMax,player._y,true) && !ground.hitTest(player._x,player.getBounds(_root).yMax,true))
  143.    {
  144.       player._x += 1;
  145.    }
  146.    while(ground.hitTest(player.getBounds(_root).xMax,player._y,true) && !ground.hitTest(player.getBounds(_root).xMin,player._y,true) && !ground.hitTest(player._x,player.getBounds(_root).yMax,true))
  147.    {
  148.       player._x -= 1;
  149.    }
  150.    while(ground.hitTest(player._x,player.getBounds(_root).yMin,true) && !ground.hitTest(player._x,player.getBounds(_root).yMax,true))
  151.    {
  152.       player._y += 0.1;
  153.    }
  154.    while(ground.hitTest(player._x,player.getBounds(_root).yMax,true))
  155.    {
  156.       fixPosition();
  157.       player._y -= 0.1;
  158.    }
  159. }
  160. function hangHit()
  161. {
  162.    while(!ground.hitTest(player.getBounds(_root).xMin - 1,player._y,true) && ground.hitTest(player.getBounds(_root).xMin - 4,player._y,true))
  163.    {
  164.       player._x -= 0.001;
  165.    }
  166.    if(hangside == "right" && !ground.hitTest(player.getBounds(_root).xMax + 4,player._y,true))
  167.    {
  168.       State = "falling";
  169.       player._x += 2;
  170.    }
  171.    else if(hangside == "left" && !ground.hitTest(player.getBounds(_root).xMin - 4,player._y,true))
  172.    {
  173.       State = "falling";
  174.       player._x -= 2;
  175.    }
  176. }
  177. function jumpHit()
  178. {
  179.    while(ground.hitTest(player.getBounds(_root).xMin + 1,player._y,true) && !ground.hitTest(player.getBounds(_root).xMax - 1,player._y,true))
  180.    {
  181.       xforce = 0;
  182.       applySpeed();
  183.       player._x += 1;
  184.    }
  185.    while(ground.hitTest(player.getBounds(_root).xMax - 1,player._y,true) && !ground.hitTest(player.getBounds(_root).xMin + 1,player._y,true))
  186.    {
  187.       xforce = 0;
  188.       applySpeed();
  189.       player._x -= 1;
  190.    }
  191.    while(ground.hitTest(player._x,player.getBounds(_root).yMin - 1,true))
  192.    {
  193.       player._y += 0.1;
  194.       yforce = 0;
  195.       player._y += yforce;
  196.    }
  197.    while(ground.hitTest(player._x,player.getBounds(_root).yMax,true))
  198.    {
  199.       player._y -= 0.1;
  200.       yforce = 0;
  201.       applySpeed();
  202.    }
  203. }
  204. function standHit()
  205. {
  206.    while(ground.hitTest(player.getBounds(_root).xMin,player._y,true) && !ground.hitTest(player.getBounds(_root).xMax,player._y,true))
  207.    {
  208.       player._x += 0.1;
  209.       xforce = Math.abs(xforce);
  210.       applySpeed();
  211.    }
  212.    while(ground.hitTest(player.getBounds(_root).xMax,player._y,true) && !ground.hitTest(player.getBounds(_root).xMin,player._y,true))
  213.    {
  214.       player._x -= 0.01;
  215.       xforce = - Math.abs(xforce);
  216.       applySpeed();
  217.    }
  218.    while(ground.hitTest(player._x,player.getBounds(_root).yMax,true))
  219.    {
  220.       player._y -= 0.001;
  221.    }
  222. }
  223. function getKeys()
  224. {
  225.    Up = Key.isDown(38);
  226.    Down = Key.isDown(40);
  227.    Left = Key.isDown(37);
  228.    Right = Key.isDown(39);
  229. }
  230. function run(amt)
  231. {
  232.    if((Right || Left) && Math.abs(xforce) < maxspeed)
  233.    {
  234.       xforce -= amt * Left;
  235.       xforce += amt * Right;
  236.    }
  237.    else
  238.    {
  239.       xforce *= 0.995;
  240.       xforce *= 0.6 * friction;
  241.    }
  242. }
  243. function seed(caller)
  244. {
  245.    if(!ground.hitTest(caller._x,caller.getBounds(_root).xMax))
  246.    {
  247.       caller._xscale = caller._yscale += 3;
  248.    }
  249. }
  250. function checkSide()
  251. {
  252.    if(ground.hitTest(player.getBounds(_root).xMax + 4,player._y,true))
  253.    {
  254.       hangside = "right";
  255.    }
  256.    else if(ground.hitTest(player.getBounds(_root).xMin - 4,player._y,true))
  257.    {
  258.       hangside = "left";
  259.    }
  260. }
  261. function animState()
  262. {
  263.    if(State == "falling")
  264.    {
  265.       player.gotoAndStop(3);
  266.       if(!ground.hitTest(player._x,player.getBounds(_root).yMax + 5,true))
  267.       {
  268.          if(Math.abs(yforce) > 5)
  269.          {
  270.             player._xscale = 80 - yforce;
  271.          }
  272.          else
  273.          {
  274.             player._xscale = 100 - yforce;
  275.          }
  276.          if(Math.abs(yforce) < 10)
  277.          {
  278.             player._rotation = (- xforce) * 5;
  279.          }
  280.       }
  281.       player.gotoAndStop(1);
  282.    }
  283.    else if(State == "standing")
  284.    {
  285.       fixPosition();
  286.       player.gotoAndStop(2);
  287.       if(xforce > 0)
  288.       {
  289.          player.stand.eyes._xscale = 100;
  290.       }
  291.       else if(xforce <= 0)
  292.       {
  293.          player.stand.eyes._xscale = -100;
  294.       }
  295.    }
  296.    else if(State == "jumping")
  297.    {
  298.       player.gotoAndStop(3);
  299.       if(!ground.hitTest(player._x,player.getBounds(_root).yMax + 5,true))
  300.       {
  301.          if(Math.abs(yforce) > 5)
  302.          {
  303.             player._xscale = 80 + yforce;
  304.          }
  305.          else
  306.          {
  307.             player._xscale = 100 - yforce;
  308.          }
  309.          if(Math.abs(yforce) < 10)
  310.          {
  311.             player._rotation = xforce * 5;
  312.          }
  313.       }
  314.    }
  315.    else if(State == "hanging")
  316.    {
  317.       fixPosition();
  318.       checkSide();
  319.       if(hangside == "left")
  320.       {
  321.          player.gotoAndStop(4);
  322.       }
  323.       else if(hangside == "right")
  324.       {
  325.          player.gotoAndStop(5);
  326.       }
  327.    }
  328. }
  329. function fixPosition()
  330. {
  331.    player._rotation = 0;
  332.    player._xscale = 100;
  333. }
  334. function playerReset()
  335. {
  336.    if(player._y > 300)
  337.    {
  338.       player._y = initialY;
  339.       player._x = initialX;
  340.       yforce = 0;
  341.       xforce = 0;
  342.    }
  343. }
  344. function playerMenu()
  345. {
  346.    if(player._x > 500)
  347.    {
  348.       playerscore = 0;
  349.       nextFrame();
  350.    }
  351. }
  352. function jumpPad(caller, amount, forced)
  353. {
  354.    if(caller.hitTest(player._x,player.getBounds(_root).yMax + 2,true) || forced == true)
  355.    {
  356.       State = "jumping";
  357.       yforce = - amount;
  358.       applySpeed();
  359.       caller.play();
  360.    }
  361. }
  362. function watchState()
  363. {
  364.    if(watchStatee.length == 3)
  365.    {
  366.       watchStatee.pop(0);
  367.    }
  368.    watchStatee.unshift(State);
  369.    if(watchStatee[0] == "standing" && watchStatee[1] == "falling" && watchStatee[2] == "standing")
  370.    {
  371.       sfError++;
  372.    }
  373.    if(watchStatee[0] == "standing" && watchStatee[1] == "falling" && watchStatee[2] == "standing" && sfError >= 3)
  374.    {
  375.       State = "falling";
  376.       player._y -= 5;
  377.       sfError = 0;
  378.    }
  379. }
  380. function fan(caller)
  381. {
  382.    if(caller.hitTest(player))
  383.    {
  384.       xforce -= 3;
  385.       yforce *= 0.3;
  386.       applySpeed();
  387.    }
  388. }
  389. function swapFrames(up, down, left, right)
  390. {
  391.    if(!up && !down && left && right)
  392.    {
  393.       if(player._x > 500)
  394.       {
  395.          nextFrame();
  396.       }
  397.       else if(player._x < 0)
  398.       {
  399.          prevFrame();
  400.       }
  401.    }
  402.    else if(!up && down && left && !right)
  403.    {
  404.       if(player._x < 0)
  405.       {
  406.          prevFrame();
  407.       }
  408.       if(player._y > 300)
  409.       {
  410.          nextFrame();
  411.       }
  412.    }
  413.    else if(up && !down && !left && right)
  414.    {
  415.       if(player._x > 500)
  416.       {
  417.          nextFrame();
  418.       }
  419.       if(player._y < 0)
  420.       {
  421.          prevFrame();
  422.       }
  423.    }
  424.    else if(up && !down && left && !right)
  425.    {
  426.       if(player._x < 0)
  427.       {
  428.          prevFrame();
  429.       }
  430.       if(player._y < 0)
  431.       {
  432.          nextFrame();
  433.       }
  434.    }
  435.    else if(!up && down && !left && right)
  436.    {
  437.       if(player._x > 500)
  438.       {
  439.          nextFrame();
  440.       }
  441.       if(player._y > 300)
  442.       {
  443.          prevFrame();
  444.       }
  445.    }
  446. }
  447. function fixLevel(vert, hori)
  448. {
  449.    if(hori)
  450.    {
  451.       initialY = player._y;
  452.       if(player._x > 490)
  453.       {
  454.          initialX = 0;
  455.          player._x = 0;
  456.       }
  457.       else if(player._x < 10)
  458.       {
  459.          initialX = 498;
  460.          player._x = 498;
  461.       }
  462.       else
  463.       {
  464.          initialX = player._x;
  465.          initialY = 298;
  466.          player._y = 298;
  467.       }
  468.    }
  469.    else if(vert)
  470.    {
  471.       if(player._x < 5)
  472.       {
  473.          initialX = 498;
  474.          player._x = 498;
  475.          initialY = player._y;
  476.       }
  477.       else if(player._x > 495)
  478.       {
  479.          initialX = 2;
  480.          player._x = 2;
  481.          initialY = player._y;
  482.       }
  483.       else
  484.       {
  485.          initialX = player._x;
  486.          if(player._y > 290)
  487.          {
  488.             initialY = 0;
  489.             player._y = 0;
  490.          }
  491.          else
  492.          {
  493.             initialY = 298;
  494.             player._y = 298;
  495.          }
  496.       }
  497.    }
  498. }
  499. function fixLevelFirst()
  500. {
  501.    initialY = player._y;
  502.    if(player._x > 250)
  503.    {
  504.       initialX = player._x + 2;
  505.    }
  506.    else
  507.    {
  508.       initialX = player._x - 2;
  509.    }
  510.    if(player._x < 15)
  511.    {
  512.       player._x = 500;
  513.    }
  514. }
  515. function time()
  516. {
  517.    playerscore += 28.57142857142857;
  518.    timer = Math.round(playerscore / 10).toString();
  519.    if(timer.length == 2)
  520.    {
  521.       timer = "time = 0." + timer.charAt(0);
  522.    }
  523.    else if(timer.length == 3)
  524.    {
  525.       timer = "time = " + timer.charAt(0) + "." + timer.charAt(1) + timer.charAt(2);
  526.    }
  527.    else if(timer.length == 4)
  528.    {
  529.       timer = "time = " + timer.charAt(0) + timer.charAt(1) + "." + timer.charAt(2) + timer.charAt(3);
  530.    }
  531.    else if(timer.length == 5)
  532.    {
  533.       timer = "time = " + timer.charAt(0) + timer.charAt(1) + timer.charAt(2) + "." + timer.charAt(3);
  534.    }
  535. }
  536. function ballPhysics(caller)
  537. {
  538.    if(Math.abs(caller.byforce) < 2 && ground.hitTest(caller._x,caller._y + 13,true))
  539.    {
  540.       caller.byforce = 0;
  541.    }
  542.    ballReset(caller);
  543.    caller.bdist = Math.sqrt(Math.pow(player._x - caller._x,2) + Math.pow(player._y - caller._y,2));
  544.    ballHit(caller);
  545.    caller._y += caller.byforce;
  546.    caller._x += caller.bxforce;
  547.    caller.bxforce *= 0.9;
  548.    caller._rotation += 7.5398223686155035 * caller.bxforce;
  549.    while(ground.hitTest(caller._x - 12.5,caller._y,true))
  550.    {
  551.       caller._x = caller._x + 1;
  552.       caller.bxforce = 0;
  553.    }
  554.    while(ground.hitTest(caller._x + 12.5,caller._y,true))
  555.    {
  556.       caller._x = caller._x - 1;
  557.       caller.bxforce = 0;
  558.       if(caller._y <= player._y)
  559.       {
  560.          caller.byforce = -5;
  561.       }
  562.    }
  563.    if(ground.hitTest(caller._x + 13,caller._y,true) || ground.hitTest(caller._x - 13,caller._y,true))
  564.    {
  565.       caller.bdist = Math.sqrt(Math.pow(player._x - caller._x,2) + Math.pow(player._y - caller._y,2));
  566.       if(caller.bdist < 17.5)
  567.       {
  568.          if(caller._y <= player._y)
  569.          {
  570.             caller._y = caller._y - 1;
  571.             caller.byforce = -5;
  572.          }
  573.       }
  574.    }
  575.    if(ground.hitTest(caller._x + 12.6,caller._y,true))
  576.    {
  577.       caller._x -= 0.02;
  578.    }
  579.    else if(ground.hitTest(caller._x - 12.6,caller._y,true))
  580.    {
  581.       caller._x += 0.02;
  582.    }
  583.    if(ground.hitTest(caller._x,caller._y + 12.5,true))
  584.    {
  585.       while(ground.hitTest(caller._x,caller._y + 12,true))
  586.       {
  587.          caller._y = caller._y - 1;
  588.       }
  589.       caller.byforce = (- caller.byforce) / 2;
  590.       if(Math.abs(caller.byforce) < 2)
  591.       {
  592.          if(!ground.hitTest(caller._x + 15,caller._y,true) && !ground.hitTest(caller._x - 15,caller._y,true))
  593.          {
  594.             caller.byforce = 0;
  595.          }
  596.       }
  597.    }
  598.    else
  599.    {
  600.       caller.byforce = caller.byforce + 1;
  601.    }
  602. }
  603. function ballHit(caller)
  604. {
  605.    if(caller.bdist < 17.5)
  606.    {
  607.       if(player._x < caller._x)
  608.       {
  609.          caller.bxforce += 2;
  610.       }
  611.       else
  612.       {
  613.          caller.bxforce -= 2;
  614.       }
  615.       if(caller._y > player._y)
  616.       {
  617.          yforce -= 3;
  618.       }
  619.    }
  620.    if(caller.bdist < 17.5)
  621.    {
  622.       caller.bdist = Math.sqrt(Math.pow(player._x - caller._x,2) + Math.pow(player._y - caller._y,2));
  623.       if(player._x < caller._x)
  624.       {
  625.          caller._x += 0.05;
  626.       }
  627.       else
  628.       {
  629.          caller._x -= 0.05;
  630.       }
  631.    }
  632. }
  633. function ballReset(caller)
  634. {
  635.    if(caller._y + 10 > 300)
  636.    {
  637.       caller._x = caller.initialX;
  638.       caller._y = caller.initialY;
  639.       caller.bxforce = 0;
  640.       caller.byforce = 0;
  641.       caller._rotation = Math.round(Math.random() * 360);
  642.    }
  643. }
  644. function fixBall(bx, by, caller)
  645. {
  646.    caller._x = bx;
  647.    caller._y = by;
  648.    caller.initialX = caller._x;
  649.    caller.initialY = caller._y;
  650. }
  651. function buttonPress(caller, victim)
  652. {
  653.    if(caller.hitTest(player) || caller.hitTest(victim))
  654.    {
  655.       if(caller.debounce != 10)
  656.       {
  657.          caller.debounce = caller.debounce + 1;
  658.       }
  659.    }
  660.    else if(caller.debounce != 0)
  661.    {
  662.       caller.debounce = caller.debounce - 1;
  663.    }
  664.    if(caller.debounce >= 5 && caller.debounce <= 10)
  665.    {
  666.       caller.nextFrame();
  667.    }
  668.    else
  669.    {
  670.       caller.prevFrame();
  671.    }
  672. }
  673. function attachFrames(caller)
  674. {
  675.    caller.gotoAndStop(ground.button._currentframe);
  676. }
  677. function oilSlick(caller)
  678. {
  679.    if(caller.hitTest(player._x,player._y + 13,true))
  680.    {
  681.       friction = 1.6666666666666667;
  682.    }
  683.    else
  684.    {
  685.       friction = 1;
  686.    }
  687. }
  688. function affectPad(caller, victim)
  689. {
  690.    if(player.hitTest(caller))
  691.    {
  692.       victim.nextFrame();
  693.    }
  694. }
  695. function groundFall(caller)
  696. {
  697.    if(player.hitTest(caller))
  698.    {
  699.       caller.play();
  700.    }
  701. }
  702. function lowGravity()
  703. {
  704.    if(ground.button._currentframe != 1)
  705.    {
  706.       yforce /= 0.95;
  707.    }
  708. }
  709. function controlVolume()
  710. {
  711.    if(vol == 100)
  712.    {
  713.       vol = 0;
  714.    }
  715.    else
  716.    {
  717.       vol = 100;
  718.    }
  719.    sound.setVolume(vol);
  720. }
  721. function reset()
  722. {
  723.    gotoAndStop("menu");
  724.    player._x = 70;
  725.    player._y = 220;
  726.    sound.start(1);
  727. }
  728. var State = "falling";
  729. var xforce = 0;
  730. var yforce = 0;
  731. var maxspeed = 5;
  732. var djump = "fresh";
  733. var hangside = "left";
  734. var watchStatee = new Array();
  735. var sfError = 0;
  736. var where = 2;
  737. var playerscore = 0;
  738. var timer;
  739. var friction = 1;
  740. var vol = 100;
  741. var sound = new Sound(song);
  742. nextFrame();
  743.