home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Aventura / FlashGauntlet.swf / scripts / DefineSprite_94 / frame_11 / DoAction.as
Encoding:
Text File  |  2001-07-14  |  2.0 KB  |  117 lines

  1. newx = _root.player._x;
  2. newy = _root.player._y;
  3. distx = int(getProperty(this, _X) - newx);
  4. disty = int(getProperty(this, _Y) - newy);
  5. if(0 < disty && 0 < distx)
  6. {
  7.    if(Math.abs(distx) < Math.abs(disty / 2))
  8.    {
  9.       with(this.ghost)
  10.       {
  11.          gotoAndStop("u");
  12.       }
  13.    }
  14.    else if(Math.abs(disty) < Math.abs(distx / 2))
  15.    {
  16.       with(this.ghost)
  17.       {
  18.          gotoAndStop("l");
  19.       }
  20.    }
  21.    else
  22.    {
  23.       with(this.ghost)
  24.       {
  25.          gotoAndStop("ul");
  26.       }
  27.    }
  28. }
  29. if(disty < 0 && 0 < distx)
  30. {
  31.    if(Math.abs(distx) < Math.abs(disty / 2))
  32.    {
  33.       with(this.ghost)
  34.       {
  35.          gotoAndStop("d");
  36.       }
  37.    }
  38.    else if(Math.abs(disty) < Math.abs(distx / 2))
  39.    {
  40.       with(this.ghost)
  41.       {
  42.          gotoAndStop("l");
  43.       }
  44.    }
  45.    else
  46.    {
  47.       with(this.ghost)
  48.       {
  49.          gotoAndStop("dl");
  50.       }
  51.    }
  52. }
  53. if(disty < 0 && distx < 0)
  54. {
  55.    if(Math.abs(distx) < Math.abs(disty / 2))
  56.    {
  57.       with(this.ghost)
  58.       {
  59.          gotoAndStop("d");
  60.       }
  61.    }
  62.    else if(Math.abs(disty) < Math.abs(distx / 2))
  63.    {
  64.       with(this.ghost)
  65.       {
  66.          gotoAndStop("r");
  67.       }
  68.    }
  69.    else
  70.    {
  71.       with(this.ghost)
  72.       {
  73.          gotoAndStop("dr");
  74.       }
  75.    }
  76. }
  77. if(0 < disty && distx < 0)
  78. {
  79.    if(Math.abs(disty) < Math.abs(distx / 2))
  80.    {
  81.       with(this.ghost)
  82.       {
  83.          gotoAndStop("r");
  84.       }
  85.    }
  86.    else if(Math.abs(distx) < Math.abs(disty / 2))
  87.    {
  88.       with(this.ghost)
  89.       {
  90.          gotoAndStop("u");
  91.       }
  92.    }
  93.    else
  94.    {
  95.       with(this.ghost)
  96.       {
  97.          gotoAndStop("ur");
  98.       }
  99.    }
  100. }
  101. z = distx * distx + disty * disty;
  102. hyp = Math.sqrt(z);
  103. speed = 4;
  104. distance = int(hyp / speed);
  105. movex = distx / distance;
  106. movey = disty / distance;
  107. if(0 >= distance)
  108. {
  109.    gotoAndPlay(1);
  110. }
  111. else
  112. {
  113.    setProperty(this, _X, getProperty(this, _X) - movex);
  114.    setProperty(this, _Y, getProperty(this, _Y) - movey);
  115.    distance -= 1;
  116. }
  117.