home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Esportes / Horse_riding.swf / scripts / frame_4 / DoAction.as
Text File  |  2008-09-23  |  13KB  |  500 lines

  1. function initialize()
  2. {
  3.    horse.attachMovie("h1","h1",1);
  4.    horse.h1._x = 100;
  5.    horse.h1._y = 250;
  6.    horse.attachMovie("h2","h2",2);
  7.    horse.h2._x = 200;
  8.    horse.h2._y = 250;
  9.    horse.attachMovie("downCount","downCount",100);
  10.    horse.downCount._x = 300;
  11.    horse.downCount._y = 150;
  12.    horse.downCount.onEnterFrame = function()
  13.    {
  14.       if(this._currentframe == 60)
  15.       {
  16.          horse.h1.h.gotoAndStop(1);
  17.          horse.h2.h.gotoAndStop(1);
  18.          difficultySet();
  19.          mie.start();
  20.          startGame();
  21.          this.onEnterFrame = null;
  22.          this.removeMovieClip();
  23.       }
  24.    };
  25. }
  26. function difficultySet()
  27. {
  28.    trace(difficulty);
  29.    if(difficulty == 1)
  30.    {
  31.       l1 = 0.15;
  32.       l2 = 0.4;
  33.       l3 = 0.9;
  34.       h2Speed = 0.02;
  35.       rndJump = 0.5;
  36.    }
  37.    else if(difficulty == 2)
  38.    {
  39.       l1 = 0.25;
  40.       l2 = 0.6;
  41.       l3 = 0.9;
  42.       h2Speed = 0.05;
  43.       rndJump = 0.9;
  44.    }
  45.    else if(difficulty == 3)
  46.    {
  47.       l1 = 0.35;
  48.       l2 = 0.7;
  49.       l3 = 0.9;
  50.       h2Speed = 0.07;
  51.       rndJump = 1;
  52.    }
  53. }
  54. function startGame()
  55. {
  56.    bs.start(0,9999);
  57.    var mouseListener = new Object();
  58.    mouseListener.onMouseDown = function()
  59.    {
  60.       if(energy > 2 && allowScroll == true)
  61.       {
  62.          horse.h1.jumpTimes = horse.h1.jumpTimes + 1;
  63.          if(horse.h1.jumpTimes <= 2)
  64.          {
  65.             horse.h1.gotoAndPlay("jump");
  66.             horse.h1.dy = 10;
  67.             horse.h1.onEnterFrame = function()
  68.             {
  69.                this.allowMoving = false;
  70.                this._y -= this.dy;
  71.                this.dy -= 0.8;
  72.                if(this._y >= 250)
  73.                {
  74.                   this.jumpTimes = 0;
  75.                   if(this.f == false)
  76.                   {
  77.                      this.allowMoving = true;
  78.                      this.gotoAndPlay("descend");
  79.                   }
  80.                   this._y = 250;
  81.                   this.onEnterFrame = null;
  82.                }
  83.             };
  84.          }
  85.       }
  86.    };
  87.    Mouse.addListener(mouseListener);
  88.    horse.h1.gotoAndPlay("gallop");
  89.    horse.h2.gotoAndPlay("gallop");
  90.    horse.h1.jumpTimes = 0;
  91.    horse.h1.allowMoving = true;
  92.    horse.h2.allowMoving = true;
  93.    horse.h2.allowJump = true;
  94.    horse.h1.f = false;
  95.    horse.h2.f = false;
  96.    energy = 100;
  97.    table_mc.flag._visible = false;
  98.    ground.onEnterFrame = function()
  99.    {
  100.       if(allowScroll == true && energy > 2 && h1Distance < allDistance && h2Distance < allDistance)
  101.       {
  102.          if(this._x < -1180)
  103.          {
  104.             this._x = 0;
  105.          }
  106.          if(hill._x < -1200)
  107.          {
  108.             hill._x = 0;
  109.          }
  110.          if(horse.h1._x < 200)
  111.          {
  112.             ground._x -= 10;
  113.             hill._x -= 3.333333;
  114.          }
  115.          else
  116.          {
  117.             ground._x -= horse.h1._x / 20;
  118.             hill._x -= horse.h1._x / 60;
  119.          }
  120.          speed = Math.floor(horse.h1._x / Stage.width * 200);
  121.          h1Distance += speed / 2000;
  122.       }
  123.       else
  124.       {
  125.          speed = 1;
  126.          if(energy < 2)
  127.          {
  128.             for(var _loc2_ in za)
  129.             {
  130.                za[_loc2_].onEnterFrame = null;
  131.             }
  132.             trace("energy");
  133.             Mouse.removeListener(mouseListener);
  134.             horse.h1.gotoAndStop(1);
  135.             horse.h2.gotoAndStop(1);
  136.             showWinLose("energy");
  137.             horse.h1.allowMoving = false;
  138.             horse.h1.f = true;
  139.             this.onEnterFrame = null;
  140.             clearInterval(itl);
  141.             clearInterval(energyItl);
  142.             clearInterval(timeItl);
  143.          }
  144.          if(h1Distance >= allDistance)
  145.          {
  146.             for(_loc2_ in za)
  147.             {
  148.                za[_loc2_].onEnterFrame = null;
  149.             }
  150.             trace("win");
  151.             Mouse.removeListener(mouseListener);
  152.             horse.h1.gotoAndStop(1);
  153.             horse.h2.gotoAndStop(1);
  154.             showWinLose("win");
  155.             horse.h1.allowMoving = false;
  156.             table_mc.flag._visible = true;
  157.             table_mc.flag._y = 6;
  158.             horse.h1.f = true;
  159.             this.onEnterFrame = null;
  160.             clearInterval(itl);
  161.             clearInterval(energyItl);
  162.             clearInterval(timeItl);
  163.          }
  164.          if(h2Distance >= allDistance)
  165.          {
  166.             for(_loc2_ in za)
  167.             {
  168.                za[_loc2_].onEnterFrame = null;
  169.             }
  170.             trace("lose");
  171.             Mouse.removeListener(mouseListener);
  172.             horse.h1.gotoAndStop(1);
  173.             horse.h2.gotoAndStop(1);
  174.             showWinLose("lose");
  175.             horse.h1.allowMoving = false;
  176.             table_mc.flag._visible = true;
  177.             table_mc.flag._y = 40;
  178.             horse.h1.f = true;
  179.             this.onEnterFrame = null;
  180.             clearInterval(itl);
  181.             clearInterval(energyItl);
  182.             clearInterval(timeItl);
  183.          }
  184.       }
  185.       if(horse.h1.allowMoving == true && horse.h1.f == false)
  186.       {
  187.          if(horse.h1._x < 600 - horse.h1._width)
  188.          {
  189.             horse.h1._x += (this._parent._xmouse - horse.h1._x) / 15;
  190.          }
  191.          else
  192.          {
  193.             horse.h1._x -= 3;
  194.          }
  195.          if(horse.h1._x > 500)
  196.          {
  197.             horse.h1._x = 500;
  198.          }
  199.       }
  200.       h2AI();
  201.       energy_mc.gotoAndStop(energy);
  202.       speed_mc.gotoAndStop(speed);
  203.       table_mc.h1.gotoAndStop(Math.floor(h1Distance));
  204.       table_mc.h2.gotoAndStop(Math.floor(h2Distance));
  205.    };
  206.    itl = setInterval(addZa,800);
  207.    energyItl = setInterval(decressEnergy,1000);
  208.    timeItl = setInterval(timeFunc,1000);
  209.    horse.h2.jump = h2Jump;
  210. }
  211. function addZa()
  212. {
  213.    if(!cZa)
  214.    {
  215.       trace(oldza + "-" + newza);
  216.       if(newza == 1)
  217.       {
  218.          w_2.gotoAndPlay(2);
  219.       }
  220.       if(newza == 2)
  221.       {
  222.          w_1.gotoAndPlay(2);
  223.       }
  224.       if(newza == 3)
  225.       {
  226.          w_3.gotoAndPlay(2);
  227.       }
  228.       newza = 0;
  229.    }
  230.    else if(allowScroll == true)
  231.    {
  232.       var _loc1_ = Math.random();
  233.       if(_loc1_ < l1)
  234.       {
  235.          newza = 1;
  236.          createZa(1);
  237.       }
  238.       else if(_loc1_ >= l1 && _loc1_ < l2)
  239.       {
  240.          newza = 2;
  241.          createZa(2);
  242.       }
  243.       else if(_loc1_ >= l2 && _loc1_ < l3)
  244.       {
  245.          newza = 3;
  246.          createZa(3);
  247.       }
  248.    }
  249.    cZa = !cZa;
  250. }
  251. function createZa(num)
  252. {
  253.    za.childNum = za.childNum + 1;
  254.    var _loc2_ = "za" + za.childNum;
  255.    za.attachMovie("za",_loc2_,za.getNextHighestDepth());
  256.    za[_loc2_].gotoAndStop(num);
  257.    za[_loc2_]._x = 1500;
  258.    za[_loc2_]._y = 300;
  259.    za[_loc2_].onEnterFrame = function()
  260.    {
  261.       if(allowScroll == true)
  262.       {
  263.          if(horse.h1._x < 200)
  264.          {
  265.             this._x -= 10;
  266.          }
  267.          else
  268.          {
  269.             this._x -= horse.h1._x / 20;
  270.          }
  271.       }
  272.       if(this.hitTest(box))
  273.       {
  274.          this.removeMovieClip();
  275.       }
  276.       if(this.box.hitTest(horse.h1.box) && this.type == 1 && horse.h1.f == false)
  277.       {
  278.          clearInterval(bugItl);
  279.          horse.h1.f = true;
  280.          allowScroll = false;
  281.          horse.h1.allowMoving = false;
  282.          ground._x -= 7.5;
  283.          hill._x -= 2.5;
  284.          this._x -= 150;
  285.          horse.h2._x -= 150;
  286.          horse.h1.f = false;
  287.          fall.start();
  288.          horse.h1.gotoAndPlay("fall");
  289.          bugItl = setInterval(bugFunc,1000);
  290.       }
  291.       if(this.box.hitTest(horse.h2.box) && horse.h2.allowJump == true && Math.random() < rndJump)
  292.       {
  293.          horse.h2.allowJump = false;
  294.          horse.h2.jump();
  295.       }
  296.       if(this.box.hitTest(horse.h2.body) && horse.h2.f == false)
  297.       {
  298.          horse.h2.f = true;
  299.          horse.h2.gotoAndPlay("fall");
  300.       }
  301.       if(this.food.hitTest(horse.h1.mouth))
  302.       {
  303.          if(this.food.type == 1)
  304.          {
  305.             if(energy < 95)
  306.             {
  307.                energy += 5;
  308.             }
  309.             eat.start();
  310.             this.food.gotoAndPlay("remove1");
  311.          }
  312.          if(this.food.type == 2 || this.food.type == 3)
  313.          {
  314.             if(energy < 90)
  315.             {
  316.                energy += 10;
  317.             }
  318.             var _loc2_ = Math.random();
  319.             if(_loc2_ < 0.5)
  320.             {
  321.                eat.start();
  322.                this.food.gotoAndPlay("remove2");
  323.             }
  324.             else
  325.             {
  326.                eat.start();
  327.                this.food.gotoAndPlay("remove3");
  328.             }
  329.          }
  330.          if(this.food.type == 4)
  331.          {
  332.             horse.h1.w1.gotoAndPlay("fly");
  333.             horse.h1.w2.gotoAndPlay("fly");
  334.             sing.start();
  335.             horse.h1.dy += 15;
  336.             this.food.gotoAndStop(1);
  337.          }
  338.       }
  339.    };
  340. }
  341. function decressEnergy()
  342. {
  343.    if(energy > 1)
  344.    {
  345.       energy -= 2;
  346.    }
  347. }
  348. function h2AI()
  349. {
  350.    horse.h2._x = horse.h1._x - (h1Distance - h2Distance) * 200;
  351.    h2Distance += h2Speed;
  352. }
  353. function h2Jump()
  354. {
  355.    this.dy = 15;
  356.    this.gotoAndPlay("jump");
  357.    this.onEnterFrame = function()
  358.    {
  359.       this._y -= this.dy;
  360.       this.dy -= 0.9;
  361.       if(this._y > 250)
  362.       {
  363.          if(this.f == false)
  364.          {
  365.             this.gotoAndPlay("descend");
  366.          }
  367.          this._y = 250;
  368.          this.allowJump = true;
  369.          this.f = false;
  370.          this.onEnterFrame = null;
  371.       }
  372.    };
  373. }
  374. function timeFunc()
  375. {
  376.    time++;
  377.    time_txt.text = time + "s";
  378.    time2_txt.text = time + "s";
  379.    if(time < 60)
  380.    {
  381.       sunColorTrans.blueOffset += 3.3;
  382.       sunColorTrans.redOffset -= 1.6;
  383.       sunColorTrans.greenOffset -= 3;
  384.       sunColorTrans.alphaOffset += 0.83;
  385.       sunTrans.colorTransform = sunColorTrans;
  386.    }
  387.    if(time > 10 && backColorTrans.redOffset < 180)
  388.    {
  389.       backColorTrans.redOffset = (time - 10) * 3;
  390.       backColorTrans.greenOffset = -1 * time;
  391.       backTrans.colorTransform = backColorTrans;
  392.       hillColorTrans.redMultiplier = 1 - 0.0121428 * time;
  393.       hillColorTrans.greenMultiplier = 1 - 0.0121428 * time;
  394.       hillColorTrans.blueMultiplier = 1 - 0.0121428 * time;
  395.       hillTrans.colorTransform = hillColorTrans;
  396.       groundColorTrans.redMultiplier = 1 - 0.0057142 * time;
  397.       groundColorTrans.greenMultiplier = 1 - 0.0057142 * time;
  398.       groundColorTrans.blueMultiplier = 1 - 0.0057142 * time;
  399.       groundTrans.colorTransform = groundColorTrans;
  400.    }
  401.    if(sun._currentframe != 100 && Math.random() < 0.7)
  402.    {
  403.       sun.nextFrame();
  404.    }
  405. }
  406. function showWinLose(str)
  407. {
  408.    winLose.swapDepths(999999);
  409.    winLose.gotoAndStop(2);
  410.    if(time - baseTime > 0)
  411.    {
  412.       winLose.flag = 1;
  413.    }
  414.    else
  415.    {
  416.       winLose.flag = -1;
  417.    }
  418.    winLose.onEnterFrame = function()
  419.    {
  420.       if(str == "win")
  421.       {
  422.          this.score_txt.text = this.score2_txt.text = 65 + (baseTime - time) * scoreVar;
  423.       }
  424.       if(str == "lose")
  425.       {
  426.          this.score_txt.text = this.score2_txt.text = 30 + (baseTime - time) * scoreVar;
  427.       }
  428.       if(str == "energy")
  429.       {
  430.          this.score_txt.text = this.score2_txt.text = 8 + Math.floor(h1Distance * scoreVar * 0.3);
  431.       }
  432.       winLose.time2_txt.text = time;
  433.    };
  434. }
  435. function bugFunc()
  436. {
  437.    if(allowScroll == false)
  438.    {
  439.       trace(bug);
  440.       horse.h1.allowMoving = true;
  441.       horse.h1.f = false;
  442.       allowScroll = true;
  443.       clearInterval(bugItl);
  444.    }
  445. }
  446. stop();
  447. var backColorTrans = new flash.geom.ColorTransform();
  448. var backTrans = new flash.geom.Transform(back);
  449. backTrans.colorTransform = backColorTrans;
  450. var hillColorTrans = new flash.geom.ColorTransform();
  451. var hillTrans = new flash.geom.Transform(hill);
  452. hillTrans.colorTransform = hillColorTrans;
  453. var groundColorTrans = new flash.geom.ColorTransform();
  454. var groundTrans = new flash.geom.Transform(ground);
  455. groundTrans.colorTransform = groundColorTrans;
  456. var sunColorTrans = new flash.geom.ColorTransform();
  457. var sunTrans = new flash.geom.Transform(sun);
  458. sunColorTrans.blueOffset -= 200;
  459. sunColorTrans.redOffset += 100;
  460. sunColorTrans.greenOffset += 180;
  461. sunColorTrans.alphaOffset -= 50;
  462. sunTrans.colorTransform = sunColorTrans;
  463. var horse = this.createEmptyMovieClip("horse",3);
  464. var za = this.createEmptyMovieClip("za",1);
  465. winLose.swapDepths(2);
  466. za.childNum = 0;
  467. var oldza = 0;
  468. var newza = 0;
  469. var cZa = false;
  470. var itl;
  471. var energyItl;
  472. var timeItl;
  473. var time = 0;
  474. var allowScroll = true;
  475. var speed = 0;
  476. var energy = 0;
  477. var h1Distance = 0;
  478. var allDistance = 100;
  479. var h2Distance = 0.5;
  480. var h2Speed;
  481. var l1;
  482. var l2;
  483. var l3;
  484. var rndJump;
  485. var baseTime = 80;
  486. var baseScore = 500;
  487. var scoreVar = 1;
  488. var bugItl;
  489. var sing = new Sound();
  490. sing.attachSound("sing");
  491. var mie = new Sound();
  492. mie.attachSound("mie");
  493. var eat = new Sound();
  494. eat.attachSound("eat");
  495. var fall = new Sound();
  496. fall.attachSound("fall");
  497. var bs = new Sound();
  498. bs.attachSound("bs");
  499. initialize();
  500.