home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Aventura / asitchintime2.swf / scripts / DefineSprite_1776 / frame_1 / DoAction.as
Encoding:
Text File  |  2005-11-09  |  5.2 KB  |  235 lines

  1. function startShake(shakePower)
  2. {
  3.    _global.s1.gotoAndPlay("shake_" + myRand(1,4));
  4.    if(!lowRes)
  5.    {
  6.       if(idShake == 0)
  7.       {
  8.          _parent.moveZone.overlay_5.debris.gotoAndPlay("play");
  9.          _parent.moveZone._y += shakePower;
  10.          idShake = setInterval(shakeIt,30);
  11.       }
  12.    }
  13. }
  14. function shakeIt()
  15. {
  16.    var curY = _parent.moveZone._y;
  17.    if(curY < -0.4)
  18.    {
  19.       curY += myRand(0.1,0.8);
  20.    }
  21.    else if(curY > 0.4)
  22.    {
  23.       curY -= myRand(0.1,0.8);
  24.    }
  25.    else
  26.    {
  27.       curY = 0;
  28.       clearInterval(idShake);
  29.       idShake = 0;
  30.    }
  31.    curY = - curY;
  32.    _parent.moveZone._y = curY;
  33. }
  34. function secretIn()
  35. {
  36.    secretDiscovered = true;
  37.    _parent.moveZone["BG_" + BGCur].gotoAndStop(2);
  38.    persoXSpeed = 0;
  39.    persoYSpeed = 0;
  40. }
  41. function secretOut()
  42. {
  43.    _parent.moveZone["BG_" + BGCur].gotoAndStop(1);
  44.    perso._x = secretInX;
  45.    perso._y = secretInY;
  46. }
  47. function setDamage(instanceName, damageAmount)
  48. {
  49.    instTemp = -1;
  50.    j = 0;
  51.    while(j < tabEnemy.length)
  52.    {
  53.       if(String(tabEnemy[j][0]) eq String(instanceName))
  54.       {
  55.          tabEnemy[j][1] += damageAmount;
  56.          instTemp = j;
  57.          break;
  58.       }
  59.       j++;
  60.    }
  61.    if(instTemp == -1)
  62.    {
  63.       tabEnemy.push([String(instanceName),damageAmount]);
  64.    }
  65. }
  66. function getDamage(instanceName)
  67. {
  68.    j = 0;
  69.    while(j < tabEnemy.length)
  70.    {
  71.       if(String(tabEnemy[j][0]) eq String(instanceName))
  72.       {
  73.          return tabEnemy[j][1];
  74.       }
  75.       j++;
  76.    }
  77.    return -1;
  78. }
  79. function death()
  80. {
  81.    persoIsDying = true;
  82.    _parent.life["life_" + _root.persoLife].gotoAndPlay("close");
  83.    _root.persoLife--;
  84.    persoAnim("death");
  85. }
  86. function damage(damageAmount)
  87. {
  88.    _root.persoHealth -= damageAmount;
  89.    frameLife = Math.round(100 / _root.persoFullHealth * (_root.persoFullHealth - _root.persoHealth));
  90.    if(idLife != 0)
  91.    {
  92.       clearInterval(idLife);
  93.    }
  94.    idLife = setInterval(animDamage,33);
  95. }
  96. function animDamage()
  97. {
  98.    if(_parent.lifeBar._currentframe >= 100 and frameLife >= 100)
  99.    {
  100.       clearInterval(idLife);
  101.       idLife = 0;
  102.       _parent.lifeBar.gotoAndStop(100);
  103.       death();
  104.    }
  105.    else if(_parent.lifeBar._currentframe < frameLife)
  106.    {
  107.       var lifeSpeed = Math.floor((_parent.lifeBar._currentframe - frameLife) / lifeBarSpeed);
  108.       _parent.lifeBar.gotoAndStop(_parent.lifeBar._currentframe - lifeSpeed);
  109.    }
  110.    else if(_parent.lifeBar._currentframe > frameLife)
  111.    {
  112.       var lifeSpeed = Math.ceil((_parent.lifeBar._currentframe - frameLife) / lifeBarSpeed);
  113.       _parent.lifeBar.gotoAndStop(_parent.lifeBar._currentframe - lifeSpeed);
  114.    }
  115.    else
  116.    {
  117.       clearInterval(idLife);
  118.       idLife = 0;
  119.    }
  120. }
  121. function persoAnim(action)
  122. {
  123.    if(persoIsDying)
  124.    {
  125.       action = "death";
  126.    }
  127.    else if(persoIsInPain)
  128.    {
  129.       action = "hit";
  130.    }
  131.    else if(persoIsInvisible)
  132.    {
  133.       action = "invisible";
  134.    }
  135.    switch(action)
  136.    {
  137.       case "idle":
  138.          if(persoIsActivating)
  139.          {
  140.             action = "activate";
  141.          }
  142.          else if(persoIsAttacking)
  143.          {
  144.             action = "attack";
  145.          }
  146.          else if(persoIsLanding)
  147.          {
  148.             action = "land";
  149.          }
  150.          break;
  151.       case "run":
  152.          if(persoIsLanding)
  153.          {
  154.             action = "land";
  155.          }
  156.          else if(persoIsAttacking)
  157.          {
  158.             action = "attack";
  159.          }
  160.          break;
  161.       case "land":
  162.          persoIsLanding = true;
  163.          break;
  164.       case "crouch":
  165.          if(persoIsAttacking)
  166.          {
  167.             action = "attack";
  168.          }
  169.          break;
  170.       case "attack":
  171.          break;
  172.       case "death":
  173.          persoXSpeed = 0;
  174.    }
  175.    if(persoCurAction ne action)
  176.    {
  177.       perso.gotoAndStop(action);
  178.       persoCurAction = action;
  179.    }
  180. }
  181. function transitTo(direction)
  182. {
  183.    _quality = "MEDIUM";
  184.    inTransit = direction;
  185.    transitNewX = (- BGWidth) * (BGCur + direction - 1);
  186.    BGLast = BGCur;
  187.    BGCur += direction;
  188.    if(_root.level == 2 and BGCur + BGLast == 5)
  189.    {
  190.       transitAccel = 1;
  191.    }
  192.    else if(_root.level == 1 and BGCur == 9)
  193.    {
  194.       transitAccel = 1;
  195.    }
  196.    else
  197.    {
  198.       transitAccel = 3.5;
  199.    }
  200.    _parent.moveZone.attachMovie("BGHit_l" + _root.level + "_" + BGCur,"BG_" + BGCur,BGCur);
  201.    _parent.moveZone.attachMovie("overlay_l" + _root.level + "_" + BGCur,"overlay_" + BGCur,101 + BGCur);
  202.    with(eval("_parent.moveZone.BG_" + BGCur))
  203.    {
  204.       _x = BGWidth * (BGCur - 1);
  205.       _y = 0;
  206.    }
  207.    with(eval("_parent.moveZone.overlay_" + BGCur))
  208.    {
  209.       _x = BGWidth * (BGCur - 1);
  210.       _y = 0;
  211.    }
  212. }
  213. function myRand(valMin, valMax)
  214. {
  215.    x = Math.round(Math.random() * (valMax - valMin)) + valMin;
  216.    return x;
  217. }
  218. function myRandDec(valMin, valMax)
  219. {
  220.    return Math.random() * (valMax - valMin) + valMin;
  221. }
  222. enemyTab = new Array();
  223. damagedEnemyTab = new Array();
  224. damagedEnemyNum = 0;
  225. inTransit = 0;
  226. transitNewX = 0;
  227. transitXSpeed = 0;
  228. accroche = 8;
  229. keyUpListener = new Object();
  230. Key.addListener(keyUpListener);
  231. stillPressingKeyUp = false;
  232. keyAttListener = new Object();
  233. Key.addListener(keyAttListener);
  234. stillPressingKeyAtt = false;
  235.