home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / 3brothers.swf / scripts / frame_4 / DoAction.as
Encoding:
Text File  |  2008-09-23  |  12.2 KB  |  542 lines

  1. this.stop();
  2. init = function()
  3. {
  4.    stop_area = 50;
  5.    control_player_num = 3;
  6.    last_control_player = 0;
  7.    create_max_itemnum = 6;
  8.    total_num = 1;
  9.    item_time = 0;
  10.    item_delay = 30;
  11.    item_min_depth = 1000;
  12.    item_max_depth = 1100;
  13.    item_depth = item_min_depth;
  14.    create_item_num = 0;
  15.    spetial_item = 80;
  16.    color_star = 10;
  17.    life_item = 3;
  18.    hurdle_time = 0;
  19.    hurdle_delay = 384;
  20.    hurdle_move_ok = false;
  21.    hurdle_speed = 8;
  22.    level = 1;
  23.    score = 0;
  24.    life = 3;
  25.    maxLife = 3;
  26.    playerPos1 = 174;
  27.    playerPos2 = 112;
  28.    playerPos3 = 50;
  29.    clicktime = 0;
  30.    minusTime = 0.1;
  31.    plusTime = 3;
  32.    clearTime = 1440;
  33.    distTime = 0;
  34.    startDist = -120;
  35.    clearDist = 283;
  36.    var _loc2_ = 1;
  37.    while(_loc2_ <= control_player_num)
  38.    {
  39.       this["player" + _loc2_].select_mc.gotoAndStop("unactive");
  40.       _loc2_ = _loc2_ + 1;
  41.    }
  42.    menuDepth = menu_mc.getDepth();
  43.    menu_mc.swapDepths(99999);
  44.    textDepth = text_mc.getDepth();
  45.    text_mc.swapDepths(100000);
  46.    pauseDepth = pause_window.getDepth();
  47.    pause_window.swapDepths(100001);
  48.    mouseDepth = mouse_mc.getDepth();
  49.    mouse_mc.swapDepths(100002);
  50.    readyAllPlayer();
  51.    countLevel("s",level);
  52.    text_mc.gotoAndPlay("start");
  53. };
  54. init();
  55. countScore = function(s, num)
  56. {
  57.    var _loc2_ = 1;
  58.    while(_loc2_ <= 6)
  59.    {
  60.       this.menu_mc.score_mc[s + _loc2_].gotoAndStop(Math.floor(num / Math.pow(10,_loc2_ - 1)) % 10 + 1);
  61.       _loc2_ = _loc2_ + 1;
  62.    }
  63. };
  64. countCombo = function(s, num)
  65. {
  66.    var _loc1_ = 1;
  67.    while(_loc1_ <= 2)
  68.    {
  69.       s.mc["s" + _loc1_].gotoAndStop(Math.floor(num / Math.pow(10,_loc1_ - 1)) % 10 + 1);
  70.       _loc1_ = _loc1_ + 1;
  71.    }
  72. };
  73. countLevel = function(s, num)
  74. {
  75.    var _loc2_ = 1;
  76.    while(_loc2_ <= 2)
  77.    {
  78.       this.menu_mc.level_mc["s" + _loc2_].gotoAndStop(Math.floor(num / Math.pow(10,_loc2_ - 1)) % 10 + 1);
  79.       _loc2_ = _loc2_ + 1;
  80.    }
  81. };
  82. playBg = function()
  83. {
  84.    var _loc2_ = 1;
  85.    while(_loc2_ <= 2)
  86.    {
  87.       if(this["bg" + _loc2_]._currentframe < this["bg" + _loc2_]._totalframes)
  88.       {
  89.          this["bg" + _loc2_].nextFrame();
  90.       }
  91.       else
  92.       {
  93.          this["bg" + _loc2_].gotoAndStop(1);
  94.       }
  95.       _loc2_ = _loc2_ + 1;
  96.    }
  97. };
  98. startGame = function()
  99. {
  100.    game_ok = true;
  101.    action_ok = true;
  102.    distTime = 0;
  103.    hurdle_time = 0;
  104.    create_item_num = 0;
  105.    hurdle_move_ok = false;
  106.    menu_mc.dist_mc._x = startDist;
  107.    removeAllItems();
  108.    initAllPlayer();
  109.    countLevel("s",level);
  110. };
  111. this.onEnterFrame = function()
  112. {
  113.    if(game_ok)
  114.    {
  115.       moveDist();
  116.       createItems();
  117.       moveItems();
  118.       catchItems();
  119.       checkHurdle();
  120.       if(hurdle_move_ok)
  121.       {
  122.          moveHurdle();
  123.       }
  124.       decreaseTime();
  125.       movePlayer();
  126.       playBg();
  127.    }
  128. };
  129. moveDist = function()
  130. {
  131.    if(distTime >= clearTime)
  132.    {
  133.       clearGame();
  134.    }
  135.    distTime++;
  136.    menu_mc.dist_mc._x = startDist + clearDist * (distTime / clearTime);
  137. };
  138. pauseGame = function()
  139. {
  140.    game_ok = false;
  141.    pause_window.nextFrame();
  142.    SoundObj.setVolume(0);
  143. };
  144. continueGame = function()
  145. {
  146.    if(life > 0 && distTime < clearTime)
  147.    {
  148.       game_ok = true;
  149.    }
  150.    if(vol == 1)
  151.    {
  152.       SoundObj.setVolume(100);
  153.    }
  154.    pause_window.prevFrame();
  155. };
  156. clearGame = function()
  157. {
  158.    game_ok = false;
  159.    level++;
  160.    if(item_delay > 10)
  161.    {
  162.       item_delay -= 4;
  163.    }
  164.    if(hurdle_delay > 240)
  165.    {
  166.       hurdle_delay -= 12;
  167.    }
  168.    minusTime *= 1.2;
  169.    if(minusTime > 0.5)
  170.    {
  171.       minusTime = 0.5;
  172.    }
  173.    var _loc2_ = 1;
  174.    while(_loc2_ <= control_player_num)
  175.    {
  176.       this["player" + _loc2_].stopDrag();
  177.       this["player" + _loc2_].gotoAndStop("clear");
  178.       this["player" + _loc2_].select_mc.gotoAndStop("unactive");
  179.       _loc2_ = _loc2_ + 1;
  180.    }
  181.    text_mc.gotoAndStop("levelup");
  182. };
  183. stopGame = function()
  184. {
  185.    game_ok = false;
  186.    removeAllItems();
  187.    var _loc2_ = 1;
  188.    while(_loc2_ <= control_player_num)
  189.    {
  190.       this["player" + _loc2_].stopDrag();
  191.       this["player" + _loc2_].gotoAndStop("gameover");
  192.       this["player" + _loc2_].select_mc.gotoAndStop("unactive");
  193.       _loc2_ = _loc2_ + 1;
  194.    }
  195.    menu_mc.swapDepths(menuDepth);
  196.    text_mc.swapDepths(textDepth);
  197.    pause_window.swapDepths(pauseDepth);
  198.    mouse_mc.swapDepths(mouseDepth);
  199.    text_mc.gotoAndStop("gameover");
  200. };
  201. nextGame = function()
  202. {
  203.    readyAllPlayer();
  204.    removeAllItems();
  205.    menu_mc.time.bar._xscale = 100;
  206.    menu_mc.dist_mc._x = startDist;
  207.    countLevel("s",level);
  208.    text_mc.gotoAndStop("start");
  209. };
  210. decreaseTime = function()
  211. {
  212.    menu_mc.time.bar._xscale -= minusTime;
  213.    if(menu_mc.time.bar._xscale < 0)
  214.    {
  215.       stopGame();
  216.    }
  217. };
  218. increaseTime = function(n)
  219. {
  220.    menu_mc.time.bar._xscale += n;
  221. };
  222. increaseMaxTime = function()
  223. {
  224.    menu_mc.time.bar._xscale = 100;
  225. };
  226. decreaseLife = function()
  227. {
  228.    if(life > 0)
  229.    {
  230.       life--;
  231.       menu_mc.life_mc.gotoAndStop(maxLife - life + 1);
  232.       menu_mc.life_mc.mc.gotoAndPlay(1);
  233.    }
  234.    if(life == 0)
  235.    {
  236.       stopGame();
  237.    }
  238. };
  239. increaseLife = function()
  240. {
  241.    if(life < maxLife)
  242.    {
  243.       life++;
  244.       menu_mc.life_mc.gotoAndStop(maxLife - life + 1);
  245.    }
  246. };
  247. createItems = function()
  248. {
  249.    if(item_time < item_delay)
  250.    {
  251.       item_time++;
  252.       return undefined;
  253.    }
  254.    item_time = 0;
  255.    item.duplicateMovieClip("item" + item_depth,item_depth);
  256.    this["item" + item_depth]._x = Stage.width + random(50);
  257.    var _loc2_ = 2 + 0.3 * level;
  258.    if(_loc2_ > 8)
  259.    {
  260.       _loc2_ = 8;
  261.    }
  262.    this["item" + item_depth].speed = _loc2_ + random(4);
  263.    this["item" + item_depth].gotoAndStop(random(3) + 1);
  264.    if(random(color_star) == 0)
  265.    {
  266.       this["item" + item_depth].mc.gotoAndStop(2);
  267.    }
  268.    else if(random(spetial_item) == 0)
  269.    {
  270.       if(random(life_item) == 0)
  271.       {
  272.          this["item" + item_depth].mc.gotoAndStop(4);
  273.       }
  274.       else
  275.       {
  276.          this["item" + item_depth].mc.gotoAndStop(3);
  277.       }
  278.    }
  279.    else
  280.    {
  281.       this["item" + item_depth].mc.gotoAndStop(1);
  282.    }
  283.    this["item" + item_depth].item_ok = true;
  284.    if(item_depth < item_max_depth)
  285.    {
  286.       item_depth++;
  287.    }
  288.    else
  289.    {
  290.       item_depth = item_min_depth;
  291.    }
  292. };
  293. moveItems = function()
  294. {
  295.    var _loc2_ = item_min_depth;
  296.    while(_loc2_ < item_max_depth)
  297.    {
  298.       if(this["item" + _loc2_].item_ok == true)
  299.       {
  300.          this["item" + _loc2_]._x -= this["item" + _loc2_].speed;
  301.          if(this["item" + _loc2_]._x < -100)
  302.          {
  303.             removeItems(this["item" + _loc2_]);
  304.          }
  305.       }
  306.       _loc2_ = _loc2_ + 1;
  307.    }
  308. };
  309. removeItems = function(mc)
  310. {
  311.    mc.removeMovieClip();
  312. };
  313. catchItems = function()
  314. {
  315.    var _loc4_ = 0;
  316.    var _loc5_ = undefined;
  317.    var _loc2_ = item_min_depth;
  318.    while(_loc2_ < item_max_depth)
  319.    {
  320.       if(this["item" + _loc2_].item_ok == true)
  321.       {
  322.          var _loc3_ = this["item" + _loc2_]._currentframe;
  323.          if(this["item" + _loc2_].hitTest(this["player" + _loc3_].mc.hitarea))
  324.          {
  325.             _loc5_ = _loc3_;
  326.             this["item" + _loc2_].item_ok = false;
  327.             if(this["item" + _loc2_].mc._currentframe == 1)
  328.             {
  329.                score += 1;
  330.                countScore("s",score);
  331.                increaseTime(plusTime);
  332.                _loc4_ = _loc4_ + 1;
  333.             }
  334.             else if(this["item" + _loc2_].mc._currentframe == 2)
  335.             {
  336.                score += 1;
  337.                countScore("s",score);
  338.                increaseTime(plusTime);
  339.                _loc4_ = _loc4_ + 1;
  340.             }
  341.             else if(this["item" + _loc2_].mc._currentframe == 3)
  342.             {
  343.                increaseMaxTime();
  344.             }
  345.             else if(this["item" + _loc2_].mc._currentframe == 4)
  346.             {
  347.                increaseLife();
  348.             }
  349.             this["item" + _loc2_].mc.m.gotoAndPlay(2);
  350.             this["combo" + _loc3_]++;
  351.          }
  352.       }
  353.       _loc2_ = _loc2_ + 1;
  354.    }
  355.    if(_loc4_ >= 2)
  356.    {
  357.       countCombo(this["player" + _loc5_].combo,_loc4_);
  358.       this["player" + _loc5_].combo.gotoAndPlay(2);
  359.       score += 1 * _loc4_;
  360.       countScore("s",score);
  361.    }
  362. };
  363. removeAllItems = function()
  364. {
  365.    var _loc2_ = item_min_depth;
  366.    while(_loc2_ < item_max_depth)
  367.    {
  368.       this["item" + _loc2_].removeMovieClip();
  369.       _loc2_ = _loc2_ + 1;
  370.    }
  371.    hurdle._x = Stage.width + 100;
  372. };
  373. readyAllPlayer = function()
  374. {
  375.    var _loc2_ = 1;
  376.    while(_loc2_ <= control_player_num)
  377.    {
  378.       this["player" + _loc2_].move_ok = false;
  379.       this["player" + _loc2_]._x = this["playerPos" + _loc2_];
  380.       this["player" + _loc2_].gotoAndStop("ready");
  381.       _loc2_ = _loc2_ + 1;
  382.    }
  383. };
  384. initAllPlayer = function()
  385. {
  386.    var _loc2_ = 1;
  387.    while(_loc2_ <= control_player_num)
  388.    {
  389.       initPlayer(this["player" + _loc2_]);
  390.       _loc2_ = _loc2_ + 1;
  391.    }
  392. };
  393. initPlayer = function(mc)
  394. {
  395.    if(game_ok)
  396.    {
  397.       menu_mc.dist_mc.gotoAndStop("go");
  398.       mc.gotoAndStop("go");
  399.       mc.action_ok = true;
  400.       click_ok = true;
  401.       mc.select_mc.gotoAndStop("unactive");
  402.       mc.mc.shadow._visible = true;
  403.       actPlayer(mc.mc);
  404.    }
  405.    else if(life == 0)
  406.    {
  407.       mc.gotoAndStop("gameover");
  408.    }
  409. };
  410. jumpPlayer = function(mc)
  411. {
  412.    if(mc.action_ok == true)
  413.    {
  414.       mc.action_ok = false;
  415.       click_ok = false;
  416.       mc.select_mc.gotoAndStop("unactive");
  417.       var _loc2_ = "jump" + (random(2) + 1);
  418.       mc.gotoAndStop(_loc2_);
  419.    }
  420. };
  421. hitPlayer = function(mc)
  422. {
  423.    menu_mc.dist_mc.gotoAndStop("miss");
  424.    decreaseLife();
  425.    click_ok = false;
  426.    mc.stopDrag();
  427.    mc.select_mc.gotoAndStop("unactive");
  428.    mc.gotoAndStop("miss");
  429. };
  430. movePlayer = function()
  431. {
  432.    var _loc2_ = 1;
  433.    while(_loc2_ <= control_player_num)
  434.    {
  435.       if(this["player" + _loc2_].move_ok)
  436.       {
  437.          this["player" + _loc2_]._x += (this["player" + _loc2_].back_pos - this["player" + _loc2_]._x) * 0.4;
  438.          if(Math.abs(this["player" + _loc2_].back_pos - this["player" + _loc2_]._x) < 3)
  439.          {
  440.             this["player" + _loc2_]._x = this["player" + _loc2_].back_pos;
  441.             this["player" + _loc2_].move_ok = false;
  442.          }
  443.       }
  444.       _loc2_ = _loc2_ + 1;
  445.    }
  446. };
  447. bg2.onPress = function()
  448. {
  449.    if(game_ok && click_ok)
  450.    {
  451.       if(Number(getTimer() - clicktime) < 400)
  452.       {
  453.          var _loc2_ = 1;
  454.          while(_loc2_ <= control_player_num)
  455.          {
  456.             this._parent["player" + _loc2_].back_pos = this._parent["playerPos" + _loc2_];
  457.             this._parent["player" + _loc2_].move_ok = true;
  458.             _loc2_ = _loc2_ + 1;
  459.          }
  460.       }
  461.       else
  462.       {
  463.          clicktime = getTimer();
  464.       }
  465.    }
  466. };
  467. resetPosition = function()
  468. {
  469. };
  470. checkDupPlayer = function()
  471. {
  472. };
  473. moveDupPlayer = function(mc)
  474. {
  475. };
  476. actPlayer = function(mc)
  477. {
  478.    mc.ctrlarea.onPress = function()
  479.    {
  480.       mc._parent.move_ok = false;
  481.       mc._parent.startDrag(false,stop_area,mc._parent._y,Stage.width - stop_area,mc._parent._y);
  482.    };
  483.    mc.ctrlarea.onRelease = function()
  484.    {
  485.       mc._parent.stopDrag();
  486.       jumpPlayer(mc._parent);
  487.    };
  488.    mc.ctrlarea.onReleaseOutside = function()
  489.    {
  490.       mc._parent.stopDrag();
  491.       mc._parent._parent.mouse_mc.prevFrame();
  492.       jumpPlayer(mc._parent);
  493.    };
  494.    mc.ctrlarea.onRollOver = function()
  495.    {
  496.       mc.shadow._visible = false;
  497.       mc._parent.select_mc.gotoAndStop("active");
  498.    };
  499.    mc.ctrlarea.onRollOut = function()
  500.    {
  501.       mc.shadow._visible = true;
  502.       mc._parent.select_mc.gotoAndStop("unactive");
  503.    };
  504. };
  505. checkHurdle = function()
  506. {
  507.    if(hurdle_time < hurdle_delay)
  508.    {
  509.       hurdle_time++;
  510.       return undefined;
  511.    }
  512.    hurdle_time = 0;
  513.    showWarning();
  514. };
  515. showWarning = function()
  516. {
  517.    warning.gotoAndPlay(2);
  518. };
  519. createHurdle = function()
  520. {
  521.    hurdle.gotoAndStop(random(3) + 1);
  522.    hurdle_move_ok = true;
  523. };
  524. moveHurdle = function()
  525. {
  526.    hurdle._x -= hurdle_speed;
  527.    if(hurdle._x < -100)
  528.    {
  529.       hurdle_move_ok = false;
  530.       hurdle._x = Stage.width + 100;
  531.    }
  532.    var _loc2_ = 1;
  533.    while(_loc2_ <= control_player_num)
  534.    {
  535.       if(hurdle.hitarea.hitTest(this["player" + _loc2_].mc.lowhit))
  536.       {
  537.          hitPlayer(this["player" + _loc2_]);
  538.       }
  539.       _loc2_ = _loc2_ + 1;
  540.    }
  541. };
  542.