home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Nave / StarWar.swf / scripts / frame_3 / DoAction.as
Encoding:
Text File  |  2005-08-05  |  763 b   |  55 lines

  1. function choosestate()
  2. {
  3.    statecounter += 1;
  4.    if(statecounter >= statelength)
  5.    {
  6.       changestate();
  7.       statecounter = 0;
  8.       statelength = random(100);
  9.    }
  10. }
  11. function changestate()
  12. {
  13.    chance = random(10);
  14.    if(chance >= 6)
  15.    {
  16.       state = "attack";
  17.    }
  18.    else if(chance >= 2)
  19.    {
  20.       state = "defend";
  21.    }
  22.    else if(chance >= 0)
  23.    {
  24.       state = "idle";
  25.    }
  26. }
  27. function fight()
  28. {
  29.    if(state == "attack")
  30.    {
  31.       attack();
  32.    }
  33.    else if(state == "defend")
  34.    {
  35.       defend();
  36.    }
  37.    else if(state == "idle")
  38.    {
  39.       idle();
  40.    }
  41. }
  42. function idle()
  43. {
  44.    enemyslowdown();
  45. }
  46. function attack()
  47. {
  48.    enemyleftturn();
  49.    enemyfire();
  50. }
  51. function defend()
  52. {
  53.    enemyforward();
  54. }
  55.