home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / carreras.swf / scripts / frame_10 / DoAction.as
Encoding:
Text File  |  2008-09-26  |  8.1 KB  |  362 lines

  1. function teclas()
  2. {
  3.    keyListener = new Object();
  4.    keyListener.onKeyDown = function()
  5.    {
  6.       var _loc2_ = Key.getCode();
  7.       if(_loc2_ == 80)
  8.       {
  9.          _root.Pause = true;
  10.       }
  11.       if(_loc2_ == 87 || _loc2_ == 38)
  12.       {
  13.          tacelerando = true;
  14.       }
  15.       if(_loc2_ == 83 || _loc2_ == 40)
  16.       {
  17.          tfrenando = true;
  18.       }
  19.       if(_loc2_ == 65 || _loc2_ == 37)
  20.       {
  21.          tgizkierda = true;
  22.       }
  23.       if(_loc2_ == 68 || _loc2_ == 39)
  24.       {
  25.          tgderexa = true;
  26.       }
  27.    };
  28.    keyListener.onKeyUp = function()
  29.    {
  30.       switch(Key.getCode())
  31.       {
  32.          case 76:
  33.             if(lfaro == true)
  34.             {
  35.                lfaro = false;
  36.             }
  37.             else
  38.             {
  39.                lfaro = true;
  40.             }
  41.             break;
  42.          case 87:
  43.             tacelerando = false;
  44.             break;
  45.          case 38:
  46.             tacelerando = false;
  47.             break;
  48.          case 83:
  49.             tfrenando = false;
  50.             break;
  51.          case 40:
  52.             tfrenando = false;
  53.             break;
  54.          case 65:
  55.             tgizkierda = false;
  56.             break;
  57.          case 37:
  58.             tgizkierda = false;
  59.             break;
  60.          case 68:
  61.             tgderexa = false;
  62.             break;
  63.          case 39:
  64.             tgderexa = false;
  65.       }
  66.    };
  67.    if(listening == false)
  68.    {
  69.       Key.addListener(keyListener);
  70.       listening = true;
  71.    }
  72. }
  73. function luces()
  74. {
  75.    if(lfaro == true)
  76.    {
  77.       this.luzmc.gotoAndStop(1);
  78.       this.coxemc.faros_mc.gotoAndStop(2);
  79.    }
  80.    else
  81.    {
  82.       this.luzmc.gotoAndStop(2);
  83.       this.coxemc.faros_mc.gotoAndStop(1);
  84.    }
  85.    if(lfrenando == true)
  86.    {
  87.       _root.coxemc.lfrenomc.gotoAndStop(2);
  88.    }
  89.    else if(lmarxatras == true)
  90.    {
  91.       _root.coxemc.lfrenomc.gotoAndStop(3);
  92.    }
  93.    else
  94.    {
  95.       _root.coxemc.lfrenomc.gotoAndStop(1);
  96.    }
  97. }
  98. function cCamera(obj)
  99. {
  100.    _root.luzmc._rotation = this.coxemc._rotation;
  101.    _root.luzmc._x = this.coxemc._x;
  102.    _root.luzmc._y = this.coxemc._y;
  103.    _root.panelmc._x = Stage.width / 2 - (_root._x - 275);
  104.    _root.panelmc._y = Stage.height / 2 - (_root._y - 200);
  105. }
  106. function detectKeys(tacel, maxspd)
  107. {
  108.    if(tacelerando == true)
  109.    {
  110.       lfrenando = false;
  111.       lmarxatras = false;
  112.       if(speed > - maxspd)
  113.       {
  114.          speed -= tacel;
  115.       }
  116.    }
  117.    else if(tfrenando == true)
  118.    {
  119.       if(speed < 0)
  120.       {
  121.          speed += tfreno;
  122.          lfrenando = true;
  123.          if(speed > 0)
  124.          {
  125.             speed = 0;
  126.             lfrenando = true;
  127.             lmarxatras = false;
  128.          }
  129.       }
  130.       else
  131.       {
  132.          lfrenando = false;
  133.       }
  134.       if(speed > -0.05)
  135.       {
  136.          if(speed < maxspd / 2)
  137.          {
  138.             speed += tacel / 2;
  139.             lmarxatras = true;
  140.          }
  141.       }
  142.    }
  143.    else if(speed < 0)
  144.    {
  145.       if(speed > -0.05)
  146.       {
  147.          speed = 0;
  148.          lfrenando = true;
  149.          lmarxatras = false;
  150.       }
  151.       else
  152.       {
  153.          speed += friction;
  154.       }
  155.    }
  156.    else if(speed < 0.05)
  157.    {
  158.       speed = 0;
  159.       lfrenando = true;
  160.       lmarxatras = false;
  161.    }
  162.    else
  163.    {
  164.       speed -= friction;
  165.    }
  166.    if(tgizkierda == true)
  167.    {
  168.       this.coxemc._rotation += speed * tmani;
  169.    }
  170.    if(tgderexa == true)
  171.    {
  172.       this.coxemc._rotation -= speed * tmani;
  173.    }
  174.    if(this.coxemc._rotation > 180)
  175.    {
  176.       _root.pistamc._y -= speed * Math.cos(0.017453292519943295 * this.coxemc._rotation);
  177.       _root.pistamc._x += speed * Math.sin(0.017453292519943295 * this.coxemc._rotation);
  178.    }
  179.    else
  180.    {
  181.       _root.pistamc._y -= speed * Math.cos(0.017453292519943295 * this.coxemc._rotation);
  182.       _root.pistamc._x += speed * Math.sin(0.017453292519943295 * this.coxemc._rotation);
  183.    }
  184. }
  185. stop();
  186. _root.coxemc.gotoAndStop(_global.coxe);
  187. _root.pistamc.gotoAndStop(_global.pista);
  188. _root.minimapmc.minimap1.gotoAndStop(_global.pista);
  189. switch(_global.coxe)
  190. {
  191.    case 1:
  192.       friction = 0.1;
  193.       tfreno = 0.2;
  194.       acel = 0.1;
  195.       tmaxspd = 8;
  196.       tmani = 0.3;
  197.       break;
  198.    case 2:
  199.       friction = 0.1;
  200.       tfreno = 0.2;
  201.       acel = 0.05;
  202.       tmaxspd = 9;
  203.       tmani = 0.2;
  204.       break;
  205.    case 3:
  206.       friction = 0.1;
  207.       tfreno = 0.2;
  208.       acel = 0.07;
  209.       tmaxspd = 7;
  210.       tmani = 0.4;
  211.       break;
  212.    case 4:
  213.       friction = 0.2;
  214.       tfreno = 0.1;
  215.       acel = 0.02;
  216.       tmaxspd = 7;
  217.       tmani = 0.4;
  218. }
  219. switch(_global.pista)
  220. {
  221.    case 1:
  222.       _root.pistamc._x = -323;
  223.       _root.pistamc._y = 251;
  224.       break;
  225.    case 2:
  226.       _root.pistamc._x = -846;
  227.       _root.pistamc._y = -29;
  228.       break;
  229.    case 3:
  230.       _root.pistamc._x = -545;
  231.       _root.pistamc._y = -41;
  232. }
  233. Pause = false;
  234. speed = 0;
  235. rstart = false;
  236. cp1 = false;
  237. cp2 = false;
  238. v1 = 0;
  239. v2 = 0;
  240. v3 = 0;
  241. lfrenando = false;
  242. lnoxe = false;
  243. lmarxatras = false;
  244. lfaro = true;
  245. timer = 0;
  246. timer2 = 0;
  247. listening = false;
  248. tacelerando = false;
  249. tfrenando = false;
  250. tgderexa = false;
  251. tgizkierda = false;
  252. accel = new Sound();
  253. accel.attachSound("accel");
  254. decel = new Sound();
  255. decel.attachSound("decel");
  256. hi_loop = new Sound();
  257. hi_loop.attachSound("hi_loop");
  258. low_loop = new Sound();
  259. low_loop.attachSound("low_loop");
  260. accel = new Sound();
  261. accel.attachSound("accel");
  262. decel = new Sound();
  263. decel.attachSound("decel");
  264. vol = 100;
  265. this.onEnterFrame = function()
  266. {
  267.    this.minimapmc.minimap1._x = _root.pistamc._x / 10 + 35;
  268.    this.minimapmc.minimap1._y = _root.pistamc._y / 10 - 15;
  269.    if(Pause == true)
  270.    {
  271.       _root.pausemc._x = 0;
  272.    }
  273.    else
  274.    {
  275.       _root.pausemc._x = 600;
  276.       if(rstart == true)
  277.       {
  278.          timer++;
  279.       }
  280.       if(rstart == false && _root.coxemc.hitTest(this.pistamc.salida))
  281.       {
  282.          rstart = true;
  283.       }
  284.       if(rstart == true && cp1 == false && cp2 == false && _root.coxemc.hitTest(this.pistamc.cp1))
  285.       {
  286.          cp1 = true;
  287.       }
  288.       if(rstart == true && cp1 == true && cp2 == false && _root.coxemc.hitTest(this.pistamc.cp2))
  289.       {
  290.          cp2 = true;
  291.       }
  292.       if(rstart == true && cp1 == true && cp2 == true && _root.coxemc.hitTest(this.pistamc.salida))
  293.       {
  294.          if(v1 == 0)
  295.          {
  296.             v1 = timer2;
  297.             _root.panelmc.v1t.text = v1;
  298.             cp1 = false;
  299.             cp2 = false;
  300.          }
  301.          else if(v2 == 0)
  302.          {
  303.             v2 = timer2 - v1;
  304.             _root.panelmc.v2t.text = v2;
  305.             cp1 = false;
  306.             cp2 = false;
  307.          }
  308.          else if(v3 == 0)
  309.          {
  310.             v3 = timer2 - (v1 + v2);
  311.             _root.panelmc.v3t.text = v3;
  312.             cp1 = false;
  313.             cp2 = false;
  314.             if(v1 < v2 && v1 < v3)
  315.             {
  316.                _root.panelmc.bestt.text = "Best: " + v1;
  317.             }
  318.             else if(v2 < v3 && v2 < v1)
  319.             {
  320.                _root.panelmc.bestt.text = "Best: " + v2;
  321.             }
  322.             else
  323.             {
  324.                _root.panelmc.bestt.text = "Best: " + v3;
  325.             }
  326.             _root.panelmc.totalt.text = "Total: " + (v1 + v2 + v3);
  327.             switch(_global.pista)
  328.             {
  329.                case 1:
  330.                   _global.t1 = v1 + v2 + v3;
  331.                   break;
  332.                case 2:
  333.                   _global.t2 = v1 + v2 + v3;
  334.                   break;
  335.                case 3:
  336.                   _global.t3 = v1 + v2 + v3;
  337.             }
  338.             _root.Pause = true;
  339.          }
  340.       }
  341.       timer2 = timer;
  342.       this.panelmc.timermc.timer.text = timer2;
  343.       this.panelmc.ckil.ckilnum.ckilltr.text = Math.abs(Math.round(speed * 12));
  344.       teclas();
  345.       if(CollisionDetection.checkForCollision(_root.coxemc,_root.pistamc.lapista))
  346.       {
  347.          detectKeys(acel,tmaxspd);
  348.       }
  349.       else
  350.       {
  351.          detectKeys(acel / 5,tmaxspd / 5);
  352.          if(speed < -2)
  353.          {
  354.             speed += friction * 2;
  355.          }
  356.       }
  357.       _root.panelmc.ckil.gotoAndStop(Math.abs(Math.round(speed * 100 / tmaxspd)));
  358.       cCamera(coxemc);
  359.       luces();
  360.    }
  361. };
  362.