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

  1. class fwg.Enemy_0 extends fwg.Enemy
  2. {
  3.    var nId;
  4.    var nRange_atk;
  5.    var nTime;
  6.    var nRadius;
  7.    var vHit;
  8.    var nY_mClip;
  9.    var mClip;
  10.    var nHealth_max;
  11.    var nDir;
  12.    var nSpeed_x;
  13.    var nMoment;
  14.    var pTarget;
  15.    var bFall;
  16.    var nSpeed_y;
  17.    var bHit;
  18.    var nHealth;
  19.    static var aRange_atk = new Array(70,100,200);
  20.    static var aOffset = new Array(20,40,100);
  21.    function Enemy_0()
  22.    {
  23.       super();
  24.       this.nId = random(3);
  25.       this.nRange_atk = fwg.Enemy_0.aRange_atk[this.nId] + random(fwg.Enemy_0.aOffset[this.nId]);
  26.       this.nTime = 0;
  27.       this.nRadius = 30;
  28.       this.vHit = new math.Vector(0,-30);
  29.       this.nY_mClip = this.mClip._y;
  30.       this.nHealth = this.nHealth_max = 100;
  31.    }
  32.    function init()
  33.    {
  34.       this.mClip.mArm_0.gotoAndStop(this.nId * 3 + 1);
  35.       this.mClip.mHead.gotoAndStop(random(this.mClip.mHead._totalframes) + 1);
  36.    }
  37.    function walk(_n)
  38.    {
  39.       if(this.nDir != _n || this.nSpeed_x == 0)
  40.       {
  41.          this.mClip.mArm_0.mClip.gotoAndStop(1);
  42.          this.nDir = _n;
  43.          this._xscale = this.nDir * 100;
  44.          this.mClip._rotation = 0;
  45.          this.nMoment = 1;
  46.          this.nSpeed_x = _n * 5;
  47.       }
  48.    }
  49.    function stand()
  50.    {
  51.       this.mClip._y = this.nY_mClip;
  52.       this.nMoment = 0;
  53.       this.nSpeed_x = 0;
  54.       this.mClip.mArm_0.mClip.gotoAndStop(1);
  55.       this.nDir = Common.vpNum(this.pTarget._x - this._x);
  56.       this._xscale = this.nDir * 100;
  57.       this.mClip.mHead._rotation = this.mClip._rotation = 0;
  58.       this.mClip.mLeg_0._rotation = 0;
  59.       this.mClip.mLeg_1._rotation = 0;
  60.       this.mClip.mLeg_0._x = 5;
  61.       this.mClip.mLeg_1._x = -5;
  62.    }
  63.    function bow(_m, x, y)
  64.    {
  65.       var _loc2_ = {x:x,y:y};
  66.       var _loc3_ = Common.getAngle(Global.GAME.pKnight,this);
  67.       _m.localToGlobal(_loc2_);
  68.       Global.GAME.mClip.globalToLocal(_loc2_);
  69.       Common.addClip("fwg.Arrow","mArrow",Global.GAME.mClip,{_x:_loc2_.x,_y:_loc2_.y,_rotation:(Math.abs(_loc3_) >= 1.5707963267948966 ? _loc3_ * Common.a2r + random(20) + 10 : _loc3_ * Common.a2r - random(20) - 10),nDir:this.nDir});
  70.    }
  71.    function fallEnd()
  72.    {
  73.       this.bFall = false;
  74.       this.nSpeed_y = 0;
  75.       this.mClip._y = this.nY_mClip;
  76.       this.setPos_0();
  77.       if(this.bHit)
  78.       {
  79.          this.nMoment = 6;
  80.          this.mClip._rotation = -90;
  81.       }
  82.       else
  83.       {
  84.          this.stand();
  85.       }
  86.       this.mClip.mArm_0.mClip.gotoAndStop(1);
  87.    }
  88.    function beHit(_l, _r)
  89.    {
  90.       this.mClip.mArm_0.mClip.gotoAndStop(1);
  91.       this.nHealth -= 10;
  92.       this.mClip._y = this.nY_mClip;
  93.       var _loc2_ = math.Vector.polar(_l,_r);
  94.       this.nSpeed_x = int(_loc2_.x);
  95.       this.nSpeed_y = int(_loc2_.y);
  96.       if(this.nSpeed_y < 0 || this.nMoment == 6 || this.bFall)
  97.       {
  98.          if(this.bHit)
  99.          {
  100.             if(this.nSpeed_y > -8)
  101.             {
  102.                this.nSpeed_y = -8;
  103.             }
  104.          }
  105.          this.bFall = true;
  106.          this.nMoment = 5;
  107.       }
  108.       else
  109.       {
  110.          this.nMoment = 4;
  111.          this.mClip._rotation = Common.rdm_2(-20,20);
  112.          this.mClip.mHead._rotation = Common.rdm_2(-30,30);
  113.       }
  114.       this.bHit = true;
  115.       this.mClip.mHead.mEye.gotoAndPlay(2);
  116.       this.nTime = 30;
  117.    }
  118.    function ckHit(_m)
  119.    {
  120.       var _loc2_ = {x:0,y:0};
  121.       var _loc3_ = new Object();
  122.       _m.localToGlobal(_loc2_);
  123.       _loc3_.x = Global.GAME.pKnight.vHit.x;
  124.       _loc3_.y = Global.GAME.pKnight.vHit.y;
  125.       Global.GAME.pKnight.localToGlobal(_loc3_);
  126.       var _loc5_ = Common.distance(_loc2_.x,_loc2_.y,_loc3_.x,_loc3_.y);
  127.       if(_loc5_ < _m.nRadius + Global.GAME.pKnight.nRadius)
  128.       {
  129.          Global.GAME.pKnight.beHit();
  130.          _loc2_.x = (_loc2_.x + _loc3_.x) / 2;
  131.          _loc2_.y = (_loc2_.y + _loc3_.y) / 2;
  132.          Global.GAME.pKnight.globalToLocal(_loc2_);
  133.          Common.addClip("mBlood",null,Global.GAME.pKnight,{_x:_loc2_.x,_y:_loc2_.y,_rotation:_m._rotation + Common.rdm_2(-60,60),_xscale:(- this.nDir) / Global.GAME.pKnight.nDir * 100});
  134.       }
  135.    }
  136.    function death()
  137.    {
  138.       this.remove();
  139.       Global.playSound("sdDeath_" + random(8));
  140.       Global.GAME.pKnight.nKill = Global.GAME.pKnight.nKill + 1;
  141.    }
  142.    function movement()
  143.    {
  144.       var _loc2_ = getTimer();
  145.       if(this.bHit)
  146.       {
  147.          switch(this.nMoment)
  148.          {
  149.             case 4:
  150.                if(this.nHealth > 0)
  151.                {
  152.                   if(this.nTime <= 0)
  153.                   {
  154.                      this.nTime = 0;
  155.                      this.bHit = false;
  156.                      this.stand();
  157.                   }
  158.                   else
  159.                   {
  160.                      this.nTime = this.nTime - 1;
  161.                   }
  162.                }
  163.                else
  164.                {
  165.                   this.death();
  166.                   delete this.onEnterFrame;
  167.                   this.onEnterFrame = null;
  168.                   new Exp(this.mClip,Global.GAME.mClip.mMid);
  169.                }
  170.                break;
  171.             case 5:
  172.                this.mClip._rotation = (- this.nSpeed_y) * 3 - 90;
  173.                break;
  174.             case 6:
  175.                this.nTime = this.nTime - 1;
  176.                if(this.nHealth > 0)
  177.                {
  178.                   if(this.nTime <= 0)
  179.                   {
  180.                      this.bHit = false;
  181.                      this.stand();
  182.                   }
  183.                   else if(this.nTime < 20)
  184.                   {
  185.                      this.mClip._rotation = (- this.nTime) * 4;
  186.                   }
  187.                }
  188.                else
  189.                {
  190.                   if(this.mClip._alpha > 99)
  191.                   {
  192.                      if(!random(3))
  193.                      {
  194.                         this.nMoment = 4;
  195.                         break;
  196.                      }
  197.                      this.death();
  198.                   }
  199.                   this.mClip._alpha -= 10;
  200.                   if(this.mClip._alpha < 0)
  201.                   {
  202.                      this.removeMovieClip();
  203.                   }
  204.                }
  205.                break;
  206.             case 7:
  207.          }
  208.       }
  209.       else
  210.       {
  211.          switch(this.nMoment)
  212.          {
  213.             case 0:
  214.                this.mClip.mHead._y = - Common.linearCycle(_loc2_,800,2) - 7;
  215.                break;
  216.             case 1:
  217.                this.mClip.mHead._y = - Common.linearCycle(_loc2_,800,2) - 7;
  218.                this.mClip.mLeg_0._rotation = 100 - Common.linearCycle(_loc2_,800,180);
  219.                this.mClip.mLeg_1._rotation = 100 - Common.linearCycle(_loc2_ + 400,800,180);
  220.                this.mClip.mArm_0._rotation = this.mClip.mLeg_0._rotation + 90;
  221.                this.mClip.mArm_1._rotation = this.mClip.mLeg_1._rotation + 90;
  222.                this.mClip.mLeg_0._x = _loc0_ = Common.linearCycle(_loc2_,800,10) - 5;
  223.                this.mClip.mArm_0._x = _loc0_;
  224.                this.mClip.mLeg_1._x = _loc0_ = Common.linearCycle(_loc2_ + 400,800,10) - 5;
  225.                this.mClip.mArm_1._x = _loc0_;
  226.                this.mClip._y = - Common.linearCycle(_loc2_ + 200,400,20) - 10;
  227.                break;
  228.             case 2:
  229.             case 3:
  230.          }
  231.       }
  232.    }
  233.    function moving()
  234.    {
  235.       if(this.nSpeed_x)
  236.       {
  237.          this._x += this.nSpeed_x;
  238.          if(!this.bFall)
  239.          {
  240.             if(this.bHit)
  241.             {
  242.                this.nSpeed_x /= 2;
  243.                this.nSpeed_x = int(this.nSpeed_x);
  244.             }
  245.             this.setPos_0();
  246.          }
  247.       }
  248.    }
  249.    function onEnterFrame()
  250.    {
  251.       if(!Global.GAME.bPause)
  252.       {
  253.          this.ctrl();
  254.          this.falling();
  255.          this.moving();
  256.          this.movement();
  257.          if(this._y > 480)
  258.          {
  259.             this.remove();
  260.             this.removeMovieClip();
  261.          }
  262.       }
  263.    }
  264.    function ctrl()
  265.    {
  266.       if(!this.bHit)
  267.       {
  268.          var _loc2_ = this.pTarget._x - this._x;
  269.          if(Math.abs(_loc2_) > this.nRange_atk)
  270.          {
  271.             if(this.nTime <= 0)
  272.             {
  273.                this.nTime = 0;
  274.                this.walk(Common.vpNum(_loc2_));
  275.             }
  276.             else
  277.             {
  278.                this.nTime -= 10;
  279.             }
  280.          }
  281.          else
  282.          {
  283.             if(this.nTime == 0)
  284.             {
  285.                this.stand();
  286.                this.nTime = 120;
  287.                this.mClip.mArm_0._rotation = 0;
  288.             }
  289.             else if(this.nTime < 100)
  290.             {
  291.                this.mClip.mArm_0.mClip.play();
  292.             }
  293.             this.nTime = this.nTime - 1;
  294.          }
  295.       }
  296.    }
  297. }
  298.