home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Aventura / tall-ships.swf / scripts / frame_11 / DoAction.as < prev   
Encoding:
Text File  |  2005-09-29  |  16.3 KB  |  626 lines

  1. function toggleQuality()
  2. {
  3.    if(Key.isDown(33))
  4.    {
  5.       _global.gameQuality = "HIGH";
  6.       _quality = "HIGH";
  7.       detailToggle_mc.gotoAndStop("up");
  8.       detailText_mc.gotoAndPlay("high");
  9.    }
  10.    else if(Key.isDown(34))
  11.    {
  12.       _global.gameQuality = "LOW";
  13.       _quality = "LOW";
  14.       detailToggle_mc.gotoAndStop("down");
  15.       detailText_mc.gotoAndPlay("low");
  16.    }
  17. }
  18. function cheatSpeed()
  19. {
  20.    if(!ship_mc.oldMaxSpeed)
  21.    {
  22.       ship_mc.oldMaxSpeed = ship_mc.maxSpeed;
  23.    }
  24.    if(Key.isDown(80))
  25.    {
  26.       ship_mc.maxSpeed = 20;
  27.    }
  28.    else
  29.    {
  30.       ship_mc.maxSpeed = ship_mc.oldMaxSpeed;
  31.    }
  32. }
  33. function fadeOut(target)
  34. {
  35.    if(target._alpha < 42)
  36.    {
  37.       target._alpha += 5;
  38.    }
  39. }
  40. function setFlags()
  41. {
  42.    if(_global.city.lisbon)
  43.    {
  44.       flagLisbon_mc.gotoAndStop("color");
  45.       flagLisbon_mc._alpha = 100;
  46.    }
  47.    if(_global.city.alexandria)
  48.    {
  49.       flagAlexandria_mc.gotoAndStop("color");
  50.       flagAlexandria_mc._alpha = 100;
  51.    }
  52.    if(_global.city.dakar)
  53.    {
  54.       flagDakar_mc.gotoAndStop("color");
  55.       flagDakar_mc._alpha = 100;
  56.    }
  57.    if(_global.city.rioDeJaneiro)
  58.    {
  59.       flagRioDeJaneiro_mc.gotoAndStop("color");
  60.       flagRioDeJaneiro_mc._alpha = 100;
  61.    }
  62.    if(_global.city.caracas)
  63.    {
  64.       flagCaracas_mc.gotoAndStop("color");
  65.       flagCaracas_mc._alpha = 100;
  66.    }
  67.    if(_global.city.newOrleans)
  68.    {
  69.       flagNewOrleans_mc.gotoAndStop("color");
  70.       flagNewOrleans_mc._alpha = 100;
  71.    }
  72.    if(_global.city.halifax)
  73.    {
  74.       flagHalifax_mc.gotoAndStop("color");
  75.       flagHalifax_mc._alpha = 100;
  76.    }
  77. }
  78. function createWaterTrail(target, x, y)
  79. {
  80.    i = target.waterTrail;
  81.    if(i % 2 && target.speed > 1.5 && Key.isDown(38))
  82.    {
  83.       map_mc.waterTrails_mc.attachMovie("waterTrail","waterTrail" + i + "_mc",300 + i);
  84.       map_mc.waterTrails_mc["waterTrail" + i + "_mc"]._x = map_mc._x * -1 + x;
  85.       map_mc.waterTrails_mc["waterTrail" + i + "_mc"]._y = map_mc._y * -1 + y;
  86.       map_mc.waterTrails_mc["waterTrail" + i + "_mc"]._rotation = target._rotation + 30;
  87.    }
  88.    if(target.waterTrail < 14)
  89.    {
  90.       target.waterTrail += 1;
  91.    }
  92.    else
  93.    {
  94.       target.waterTrail = 0;
  95.    }
  96. }
  97. function updateTimer()
  98. {
  99.    if(!ship_mc.finished && !timer.outOfTime)
  100.    {
  101.       if(timer.milliseconds == 0)
  102.       {
  103.          timer.milliseconds = 9;
  104.          timer.seconds -= 1;
  105.       }
  106.       else
  107.       {
  108.          timer.milliseconds -= 1;
  109.       }
  110.       if(timer.seconds <= 0 && timer.milliseconds <= 0)
  111.       {
  112.          clearInterval(timerInterval);
  113.          timer.seconds = 0;
  114.          timer.milliseconds = 0;
  115.          timer.outOfTime = true;
  116.          outOfTime_txt.text = "You\'re out of time.\nPress \"spacebar\" to try again.";
  117.       }
  118.       timer_txt.text = timer.seconds + "." + timer.milliseconds;
  119.    }
  120. }
  121. function restartLeg()
  122. {
  123.    if(Key.isDown(32))
  124.    {
  125.       clearInterval(timerInterval);
  126.       movingSound.stop();
  127.       _global.city[_global.nextCity] = false;
  128.       gotoAndStop("restart");
  129.       play();
  130.    }
  131. }
  132. function restartRace()
  133. {
  134.    if(Key.isDown(36))
  135.    {
  136.       clearInterval(timerInterval);
  137.       movingSound.stop();
  138.       gotoAndStop("selectBoat");
  139.       play();
  140.    }
  141. }
  142. function startNextLeg()
  143. {
  144.    if(Key.isDown(35) || Key.isDown(13))
  145.    {
  146.       clearInterval(timerInterval);
  147.       movingSound.stop();
  148.       switch(_global.leg)
  149.       {
  150.          case "london":
  151.             _global.londonSeconds = timer.seconds;
  152.             _global.londonMilliseconds = timer.milliseconds;
  153.             _global.leg = "lisbon";
  154.             _global.nextCity = "alexandria";
  155.             _global.nextDock = "alexandriaDock_mc";
  156.             _global.shipRotation = 45;
  157.             _global.startSeconds = 60;
  158.             _global.startMilliseconds = 0;
  159.             gotoAndStop("restart");
  160.             play();
  161.             break;
  162.          case "lisbon":
  163.             _global.lisbonSeconds = timer.seconds;
  164.             _global.lisbonMilliseconds = timer.milliseconds;
  165.             _global.leg = "alexandria";
  166.             _global.nextCity = "dakar";
  167.             _global.nextDock = "dakarDock_mc";
  168.             _global.shipRotation = 180;
  169.             _global.startSeconds = 60;
  170.             _global.startMilliseconds = 0;
  171.             gotoAndStop("restart");
  172.             play();
  173.             break;
  174.          case "alexandria":
  175.             _global.alexandriaSeconds = timer.seconds;
  176.             _global.alexandriaMilliseconds = timer.milliseconds;
  177.             _global.leg = "dakar";
  178.             _global.nextCity = "rioDeJaneiro";
  179.             _global.nextDock = "rioDeJaneiroDock_mc";
  180.             _global.shipRotation = 90;
  181.             _global.startSeconds = 14;
  182.             _global.startMilliseconds = 0;
  183.             gotoAndStop("restart");
  184.             play();
  185.             break;
  186.          case "dakar":
  187.             _global.dakarSeconds = timer.seconds;
  188.             _global.dakarMilliseconds = timer.milliseconds;
  189.             _global.leg = "rioDeJaneiro";
  190.             _global.nextCity = "caracas";
  191.             _global.nextDock = "caracasDock_mc";
  192.             _global.shipRotation = 330;
  193.             _global.startSeconds = 60;
  194.             _global.startMilliseconds = 0;
  195.             gotoAndStop("restart");
  196.             play();
  197.             break;
  198.          case "rioDeJaneiro":
  199.             _global.rioDeJaneiroSeconds = timer.seconds;
  200.             _global.rioDeJaneiroMilliseconds = timer.milliseconds;
  201.             _global.leg = "caracas";
  202.             _global.nextCity = "newOrleans";
  203.             _global.nextDock = "newOrleansDock_mc";
  204.             _global.shipRotation = 195;
  205.             _global.startSeconds = 25;
  206.             _global.startMilliseconds = 0;
  207.             gotoAndStop("restart");
  208.             play();
  209.             break;
  210.          case "caracas":
  211.             _global.caracasSeconds = timer.seconds;
  212.             _global.caracasMilliseconds = timer.milliseconds;
  213.             _global.leg = "newOrleans";
  214.             _global.nextCity = "halifax";
  215.             _global.nextDock = "halifaxDock_mc";
  216.             _global.shipRotation = 340;
  217.             _global.startSeconds = 20;
  218.             _global.startMilliseconds = 0;
  219.             gotoAndStop("restart");
  220.             play();
  221.             break;
  222.          case "newOrleans":
  223.             _global.newOrleansSeconds = timer.seconds;
  224.             _global.newOrleansMilliseconds = timer.milliseconds;
  225.             _global.leg = "finish";
  226.             gotoAndStop("finish");
  227.             play();
  228.       }
  229.    }
  230. }
  231. function hitLand(target)
  232. {
  233.    if(map_mc.continents_mc.hitTest(target._x,target._y,true))
  234.    {
  235.       target.hitLand = true;
  236.    }
  237.    else
  238.    {
  239.       target.hitLand = false;
  240.    }
  241. }
  242. function hitIceBergs(target)
  243. {
  244.    if(map_mc.iceBergs_mc.hitTest(target._x,target._y,true))
  245.    {
  246.       target.hitIceBerg = true;
  247.    }
  248.    else
  249.    {
  250.       target.hitIceBerg = false;
  251.    }
  252. }
  253. function hitRocks(target)
  254. {
  255.    if(map_mc.rocks_mc.hitTest(target._x,target._y,true))
  256.    {
  257.       target.hitRock = true;
  258.    }
  259.    else
  260.    {
  261.       target.hitRock = false;
  262.    }
  263. }
  264. function hitStorms(target)
  265. {
  266.    if(stormLayer_mc.hitTest(target._x,target._y,true))
  267.    {
  268.       target.hitStorm = true;
  269.    }
  270.    else
  271.    {
  272.       target.hitStorm = false;
  273.    }
  274. }
  275. function hitWhales(target)
  276. {
  277.    if(map_mc.whales_mc.hitTest(target._x,target._y,true))
  278.    {
  279.       target.hitWhale = true;
  280.    }
  281.    else
  282.    {
  283.       target.hitWhale = false;
  284.    }
  285. }
  286. function hitDock(target, dock)
  287. {
  288.    if(map_mc.docks_mc[_global.nextDock].hitTest(target._x,target._y,true) && target.speed < 0.5 && target.momentumSpeed < 0.5)
  289.    {
  290.       if(!target.city[_global.nextCity])
  291.       {
  292.          clearInterval(timerInterval);
  293.          movingSound.stop();
  294.          welcomeText_mc.gotoAndPlay(_global.nextCity);
  295.          cheeringSound = new Sound(this);
  296.          cheeringSound.attachSound("cheering");
  297.          cheeringSound.start();
  298.          target.finished = true;
  299.          _global.city[_global.nextCity] = true;
  300.          setFlags();
  301.          nextPortArrow_mc.removeMovieClip();
  302.          _quality = "HIGH";
  303.       }
  304.    }
  305. }
  306. function moveBG(target, bg)
  307. {
  308.    bg._x -= Math.cos(target.radians) * target.speed + Math.cos(target.momentumRad) * target.momentumSpeed;
  309.    bg._y -= Math.sin(target.radians) * target.speed + Math.sin(target.momentumRad) * target.momentumSpeed;
  310. }
  311. function moveClouds(target, bg)
  312. {
  313.    bg._x -= (Math.cos(target.radians) * target.speed + Math.cos(target.momentumRad) * target.momentumSpeed) * 2;
  314.    bg._y -= (Math.sin(target.radians) * target.speed + Math.sin(target.momentumRad) * target.momentumSpeed) * 2;
  315. }
  316. function turnIt(target)
  317. {
  318.    if(Key.isDown(37))
  319.    {
  320.       target._rotation -= target.turning;
  321.       target.degrees -= target.turning;
  322.       if(target.degrees < 0)
  323.       {
  324.          target.degrees += 360;
  325.       }
  326.       shipLayer_mc.ship3d_mc.gotoAndStop(Math.floor(target.degrees / 12));
  327.    }
  328.    if(Key.isDown(39))
  329.    {
  330.       target._rotation += target.turning;
  331.       target.degrees += target.turning;
  332.       if(target.degrees > 360)
  333.       {
  334.          target.degrees -= 360;
  335.       }
  336.       shipLayer_mc.ship3d_mc.gotoAndStop(Math.floor(target.degrees / 12));
  337.    }
  338.    if(target.hitStorm)
  339.    {
  340.       if(!_global.thunderPlaying)
  341.       {
  342.          thunderSound.start();
  343.          _global.thunderPlaying = true;
  344.       }
  345.       target._rotation += target.turning * 2;
  346.       target.degrees += target.turning * 2;
  347.       if(target.degrees > 360)
  348.       {
  349.          target.degrees -= 360;
  350.       }
  351.       shipLayer_mc.ship3d_mc.gotoAndStop(Math.floor(target.degrees / 12));
  352.    }
  353.    target.radians = (target._rotation + 30) * 3.141592653589793 / 180;
  354. }
  355. function changeSpeed(target)
  356. {
  357.    target.momentumSpeed *= 0.97;
  358.    if(target.momentumSpeed < 0.05)
  359.    {
  360.       target.momentumSpeed = 0;
  361.    }
  362.    if(Key.isDown(38) && target.speed < target.maxSpeed)
  363.    {
  364.       target.speed += target.acceleration;
  365.       if(target.speed > target.maxSpeed)
  366.       {
  367.          target.speed = target.maxSpeed;
  368.       }
  369.       if(target.momentumSpeed < target.speed)
  370.       {
  371.          target.momentumSpeed = target.speed;
  372.       }
  373.       target.momentumRad = target.radians;
  374.    }
  375.    else
  376.    {
  377.       target.speed *= 0.96;
  378.    }
  379.    if(Key.isDown(40) && target.speed > 0)
  380.    {
  381.       target.speed -= target.braking;
  382.       if(target.speed < 0.05)
  383.       {
  384.          target.speed = 0;
  385.       }
  386.    }
  387.    if(target.speed < 0.05)
  388.    {
  389.       target.speed = 0;
  390.    }
  391.    if(target.hitLand)
  392.    {
  393.       target.speed = 0.5;
  394.       target.momentumSpeed = 0;
  395.       if(pointsMinus_mc._currentframe == 1)
  396.       {
  397.          pointsMinus_mc.displayText = "4";
  398.          pointsMinus_mc.gotoAndPlay("start");
  399.          if(timer.seconds >= 4)
  400.          {
  401.             timer.seconds -= 4;
  402.          }
  403.          else
  404.          {
  405.             timer.seconds = 0;
  406.          }
  407.       }
  408.    }
  409.    else if(target.hitIceBerg)
  410.    {
  411.       target.speed = 0.5;
  412.       target.momentumSpeed = 0;
  413.       if(pointsMinus_mc._currentframe == 1)
  414.       {
  415.          pointsMinus_mc.displayText = "3";
  416.          pointsMinus_mc.gotoAndPlay("start");
  417.          if(timer.seconds >= 3)
  418.          {
  419.             timer.seconds -= 3;
  420.          }
  421.          else
  422.          {
  423.             timer.seconds = 0;
  424.          }
  425.       }
  426.    }
  427.    else if(target.hitRock)
  428.    {
  429.       target.speed = 0.5;
  430.       target.momentumSpeed = 0;
  431.       if(pointsMinus_mc._currentframe == 1)
  432.       {
  433.          pointsMinus_mc.displayText = "2";
  434.          pointsMinus_mc.gotoAndPlay("start");
  435.          if(timer.seconds >= 2)
  436.          {
  437.             timer.seconds -= 2;
  438.          }
  439.          else
  440.          {
  441.             timer.seconds = 0;
  442.          }
  443.       }
  444.    }
  445.    else if(target.hitWhale)
  446.    {
  447.       target.speed = 0.5;
  448.       target.momentumSpeed = 0;
  449.       if(pointsMinus_mc._currentframe == 1)
  450.       {
  451.          pointsMinus_mc.displayText = "3";
  452.          pointsMinus_mc.gotoAndPlay("start");
  453.          if(timer.seconds >= 3)
  454.          {
  455.             timer.seconds -= 3;
  456.          }
  457.          else
  458.          {
  459.             timer.seconds = 0;
  460.          }
  461.       }
  462.    }
  463.    movingSound.setVolume(target.speed * 10 + target.momentumSpeed * 10);
  464. }
  465. stop();
  466. _quality = _global.gameQuality;
  467. detailToggle_mc._visible = true;
  468. soundToggle_mc._visible = true;
  469. soundToggle_mc.onRelease = function()
  470. {
  471.    if(openingSound.getVolume() > 0)
  472.    {
  473.       soundToggle_mc.gotoAndStop("down");
  474.       openingSound.setVolume(0);
  475.    }
  476.    else
  477.    {
  478.       soundToggle_mc.gotoAndStop("up");
  479.       openingSound.setVolume(100);
  480.    }
  481. };
  482. ship_mc._rotation = _global.shipRotation;
  483. switch(_global.shipClass)
  484. {
  485.    case "A":
  486.       shipLayer_mc.attachMovie("shipA","ship3d_mc",1);
  487.       shipLayer_mc.ship3d_mc._x = 231;
  488.       shipLayer_mc.ship3d_mc._y = 178;
  489.       ship_mc.radians = (ship_mc._rotation + 30) * 3.141592653589793 / 180;
  490.       ship_mc.maxSpeed = 6;
  491.       ship_mc.acceleration = 0.1;
  492.       ship_mc.braking = 2;
  493.       ship_mc.turning = 12;
  494.       break;
  495.    case "B":
  496.       shipLayer_mc.attachMovie("shipB","ship3d_mc",1);
  497.       shipLayer_mc.ship3d_mc._x = 231;
  498.       shipLayer_mc.ship3d_mc._y = 178;
  499.       ship_mc.radians = (ship_mc._rotation + 30) * 3.141592653589793 / 180;
  500.       ship_mc.maxSpeed = 5.5;
  501.       ship_mc.acceleration = 0.2;
  502.       ship_mc.braking = 2;
  503.       ship_mc.turning = 12;
  504.       break;
  505.    case "C":
  506.       shipLayer_mc.attachMovie("shipC","ship3d_mc",1);
  507.       shipLayer_mc.ship3d_mc._x = 231;
  508.       shipLayer_mc.ship3d_mc._y = 178;
  509.       ship_mc.radians = (ship_mc._rotation + 30) * 3.141592653589793 / 180;
  510.       ship_mc.maxSpeed = 5;
  511.       ship_mc.acceleration = 0.5;
  512.       ship_mc.braking = 2;
  513.       ship_mc.turning = 12;
  514. }
  515. ship_mc.degrees = _global.shipRotation;
  516. shipLayer_mc.ship3d_mc.gotoAndStop(Math.floor(ship_mc.degrees / 12));
  517. ship_mc.momentumRad = ship_mc.radians;
  518. ship_mc.momentumSpeed = 0;
  519. ship_mc.speed = 0;
  520. ship_mc.waterTrail = 0;
  521. ship_mc.orangeBuoys = 0;
  522. ship_mc.hitLand = false;
  523. ship_mc.hitIceBerg = false;
  524. ship_mc.hitRock = false;
  525. ship_mc.hitStorm = false;
  526. ship_mc.finished = false;
  527. ship_mc.onEnterFrame = function()
  528. {
  529.    if(!ship_mc.finished && !timer.outOfTime)
  530.    {
  531.       toggleQuality();
  532.       moveBG(this,map_mc);
  533.       changeSpeed(this);
  534.       turnIt(this);
  535.       hitLand(this);
  536.       hitDock(this,_global.nextDock);
  537.       hitIceBergs(this);
  538.       hitRocks(this);
  539.       hitStorms(this);
  540.       hitWhales(this);
  541.       restartRace();
  542.       restartLeg();
  543.    }
  544.    else if(ship_mc.finished)
  545.    {
  546.       startNextLeg();
  547.       restartRace();
  548.       fadeOut(fadeToBlack_mc);
  549.    }
  550.    else if(timer.outOfTime)
  551.    {
  552.       restartLeg();
  553.       restartRace();
  554.       fadeOut(fadeToBlack_mc);
  555.    }
  556. };
  557. thunderSound = new Sound(this);
  558. thunderSound.attachSound("thunder");
  559. thunderSound.onSoundComplete = function()
  560. {
  561.    _global.thunderPlaying = false;
  562. };
  563. movingSound.stop();
  564. movingSound = new Sound(ship_mc);
  565. movingSound.attachSound("moving");
  566. movingSound.start(0,2);
  567. detailToggle_mc.onRelease = function()
  568. {
  569.    if(_global.gameQuality == "LOW")
  570.    {
  571.       _global.gameQuality = "HIGH";
  572.       _quality = "HIGH";
  573.       detailToggle_mc.gotoAndStop("up");
  574.       detailText_mc.gotoAndPlay("high");
  575.    }
  576.    else if(_global.gameQuality == "HIGH")
  577.    {
  578.       _global.gameQuality = "LOW";
  579.       _quality = "LOW";
  580.       detailToggle_mc.gotoAndStop("down");
  581.       detailText_mc.gotoAndPlay("low");
  582.    }
  583. };
  584. attachMovie("nextPortArrow","nextPortArrow_mc",8989);
  585. nextPortArrow_mc._x = 218;
  586. nextPortArrow_mc._y = 164;
  587. nextPortArrow_mc.onEnterFrame = function()
  588. {
  589.    portY = map_mc._y + map_mc.docks_mc[_global.nextDock]._y - 164;
  590.    portX = map_mc._x + map_mc.docks_mc[_global.nextDock]._x - 218;
  591.    angle = Math.atan2(portY,portX);
  592.    angle = angle * 180 / 3.141592653589793;
  593.    nextPortArrow_mc._rotation = angle;
  594. };
  595. timer = new Object();
  596. timer.outOfTime = false;
  597. timer.seconds = _global.startSeconds;
  598. timer.milliseconds = _global.startMilliseconds;
  599. timerInterval = setInterval(updateTimer,100);
  600. cloudLayer_mc.attachMovie("clouds","clouds_mc",200);
  601. cloudLayer_mc.clouds_mc._alpha = 80;
  602. cloudLayer_mc.clouds_mc.onEnterFrame = function()
  603. {
  604.    if(!ship_mc.finished && !timer.outOfTime)
  605.    {
  606.       moveClouds(ship_mc,this);
  607.    }
  608.    if(this._x > 1000)
  609.    {
  610.       this._x = -1000;
  611.    }
  612.    if(this._x < -1000)
  613.    {
  614.       this._x = 1000;
  615.    }
  616.    if(this._y > 700)
  617.    {
  618.       this._y = -700;
  619.    }
  620.    if(this._y < -700)
  621.    {
  622.       this._y = 700;
  623.    }
  624. };
  625. setFlags();
  626.