home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Acao / fwg_knight.swf / scripts / __Packages / fwg / Enemy_1.as < prev    next >
Encoding:
Text File  |  2008-08-28  |  5.7 KB  |  206 lines

  1. class fwg.Enemy_1 extends MovieClip
  2. {
  3.    var nY;
  4.    var nR;
  5.    var nSpeed_x;
  6.    var nSpeed_y;
  7.    var nMoment;
  8.    var bFall;
  9.    var nDir;
  10.    var pTarget;
  11.    var nRange_atk;
  12.    var nTime;
  13.    var nRadius;
  14.    var vHit;
  15.    var nHealth_max;
  16.    var mClip;
  17.    var __nHealth;
  18.    var mHealth;
  19.    var bHit;
  20.    var nHealth;
  21.    function Enemy_1()
  22.    {
  23.       super();
  24.       this._y += Common.rdm_2(-50,20);
  25.       this.nY = this._y;
  26.       this.nR = 0;
  27.       this.nSpeed_x = 0;
  28.       this.nSpeed_y = 0;
  29.       this.nMoment = 0;
  30.       this.bFall = true;
  31.       this.nDir = 1;
  32.       this.pTarget = Global.GAME.pKnight;
  33.       Global.GAME.aEnemy.push(this);
  34.       this.nRange_atk = 250 + random(100);
  35.       this.nTime = 0;
  36.       this.nRadius = 40;
  37.       this.vHit = new math.Vector(0,0);
  38.       this.nHealth = this.nHealth_max = 200;
  39.    }
  40.    function init()
  41.    {
  42.       this.mClip.mHead.gotoAndStop(random(this.mClip.mHead._totalframes) + 1);
  43.    }
  44.    function get nHealth()
  45.    {
  46.       return this.__nHealth;
  47.    }
  48.    function set nHealth(_nHealth)
  49.    {
  50.       this.__nHealth = _nHealth;
  51.       this.mHealth.mClip._xscale = this.__nHealth / this.nHealth_max * 100;
  52.    }
  53.    function walk(_n)
  54.    {
  55.       if(this.nDir != _n || this.nSpeed_x == 0)
  56.       {
  57.          this.mClip.mArm_0.mClip.gotoAndStop(1);
  58.          this.nDir = _n;
  59.          this._xscale = this.nDir * 100;
  60.          this.mClip._rotation = 0;
  61.          this.nMoment = 1;
  62.          this.nSpeed_x = _n * 9;
  63.       }
  64.    }
  65.    function bow(_m, x, y)
  66.    {
  67.       var _loc2_ = {x:x,y:y};
  68.       _m.localToGlobal(_loc2_);
  69.       Global.GAME.mClip.globalToLocal(_loc2_);
  70.       var _loc3_ = Common.getAngle(Global.GAME.pKnight,this);
  71.       Common.addClip("fwg.Arrow_2","mArrow_2",Global.GAME.mClip,{_x:_loc2_.x,_y:_loc2_.y,_rotation:(Math.abs(_loc3_) >= 1.5707963267948966 ? _loc3_ * Common.a2r + random(40) + 10 : _loc3_ * Common.a2r - random(40) - 10),nDir:this.nDir});
  72.    }
  73.    function fallEnd()
  74.    {
  75.    }
  76.    function beHit(_l, _r)
  77.    {
  78.       this.nMoment = 4;
  79.       this.mClip.mHead.mEye.gotoAndPlay(2);
  80.       this.bHit = true;
  81.       this.nHealth -= 10;
  82.       this.nTime = 30;
  83.    }
  84.    function movement()
  85.    {
  86.       var _loc2_ = getTimer();
  87.       if(this.bHit)
  88.       {
  89.          switch(this.nMoment)
  90.          {
  91.             case 4:
  92.                if(this.nHealth > 0)
  93.                {
  94.                   this.mClip.mArm._rotation = - Common.linearCycle(_loc2_,800,30);
  95.                   this.mClip.mArm._yscale = 100 - Common.linearCycle(_loc2_,800,200);
  96.                   this.mClip.mHead._rotation = Common.linearCycle(_loc2_ + 100,800,30);
  97.                   this.mClip._y = - Common.linearCycle(_loc2_,800,20);
  98.                   this.mClip._rotation = - Common.linearCycle(_loc2_ + 100,800,30);
  99.                   this.mClip.mLeg._rotation = - Common.linearCycle(_loc2_,800,60);
  100.                   if(this.nTime <= 0)
  101.                   {
  102.                      this.nTime = 0;
  103.                      this.bHit = false;
  104.                      this.nMoment = 0;
  105.                   }
  106.                   else
  107.                   {
  108.                      this.nTime = this.nTime - 1;
  109.                   }
  110.                }
  111.                else
  112.                {
  113.                   this.nSpeed_x = 0;
  114.                   this.nMoment = 6;
  115.                   this.remove();
  116.                }
  117.                break;
  118.             case 5:
  119.                break;
  120.             case 6:
  121.                if(this.mClip._alpha > 90)
  122.                {
  123.                   this.remove();
  124.                }
  125.                this.mClip._alpha -= 10;
  126.                if(this.mClip._alpha < 0)
  127.                {
  128.                   Global.GAME.pKnight.nKill = Global.GAME.pKnight.nKill + 1;
  129.                   Global.GAME.nScore += 5;
  130.                   Global.playSound("sdDeath_d");
  131.                   this.removeMovieClip();
  132.                }
  133.                break;
  134.             case 7:
  135.          }
  136.       }
  137.       else
  138.       {
  139.          switch(this.nMoment)
  140.          {
  141.             case 0:
  142.             case 1:
  143.                this.mClip.mArm._rotation = - Common.linearCycle(_loc2_,800,30);
  144.                this.mClip.mArm._yscale = 100 - Common.linearCycle(_loc2_,800,200);
  145.                this.mClip.mHead._rotation = Common.linearCycle(_loc2_ + 100,800,30);
  146.                this.mClip._y = - Common.linearCycle(_loc2_,800,20);
  147.                this.mClip._rotation = - Common.linearCycle(_loc2_ + 100,800,30);
  148.                this.mClip.mLeg._rotation = - Common.linearCycle(_loc2_,800,60);
  149.                break;
  150.             case 2:
  151.             case 3:
  152.          }
  153.       }
  154.    }
  155.    function moving()
  156.    {
  157.       var _loc2_ = getTimer();
  158.       this._x += this.nSpeed_x;
  159.       this._y += this.nSpeed_y;
  160.       if(Math.abs(this._y - this.nY) > 50)
  161.       {
  162.          this.nSpeed_y = Common.vpNum(this.nY - this._y);
  163.       }
  164.       else
  165.       {
  166.          this.nSpeed_y == 0 && (this.nSpeed_y = -1);
  167.       }
  168.    }
  169.    function onEnterFrame()
  170.    {
  171.       if(!Global.GAME.bPause)
  172.       {
  173.          this.ctrl();
  174.          this.moving();
  175.          this.movement();
  176.       }
  177.    }
  178.    function ctrl()
  179.    {
  180.       if(!this.bHit)
  181.       {
  182.          var _loc2_ = this.pTarget._x - this._x;
  183.          if(Math.abs(_loc2_) > this.nRange_atk)
  184.          {
  185.             this.walk(Common.vpNum(_loc2_));
  186.          }
  187.          else if(this.nTime == 0)
  188.          {
  189.             if(Common.vpNum(_loc2_) == this.nDir)
  190.             {
  191.                this.bow(this.mClip.mHead,50,10);
  192.                this.nTime = 60;
  193.             }
  194.          }
  195.          else
  196.          {
  197.             this.nTime = this.nTime - 1;
  198.          }
  199.       }
  200.    }
  201.    function remove()
  202.    {
  203.       Common.removeArray(Global.GAME.aEnemy,this);
  204.    }
  205. }
  206.