home *** CD-ROM | disk | FTP | other *** search
- class fwg.Enemy_0 extends fwg.Enemy
- {
- var nId;
- var nRange_atk;
- var nTime;
- var nRadius;
- var vHit;
- var nY_mClip;
- var mClip;
- var nHealth_max;
- var nDir;
- var nSpeed_x;
- var nMoment;
- var pTarget;
- var bFall;
- var nSpeed_y;
- var bHit;
- var nHealth;
- static var aRange_atk = new Array(70,100,200);
- static var aOffset = new Array(20,40,100);
- function Enemy_0()
- {
- super();
- this.nId = random(3);
- this.nRange_atk = fwg.Enemy_0.aRange_atk[this.nId] + random(fwg.Enemy_0.aOffset[this.nId]);
- this.nTime = 0;
- this.nRadius = 30;
- this.vHit = new math.Vector(0,-30);
- this.nY_mClip = this.mClip._y;
- this.nHealth = this.nHealth_max = 100;
- }
- function init()
- {
- this.mClip.mArm_0.gotoAndStop(this.nId * 3 + 1);
- this.mClip.mHead.gotoAndStop(random(this.mClip.mHead._totalframes) + 1);
- }
- function walk(_n)
- {
- if(this.nDir != _n || this.nSpeed_x == 0)
- {
- this.mClip.mArm_0.mClip.gotoAndStop(1);
- this.nDir = _n;
- this._xscale = this.nDir * 100;
- this.mClip._rotation = 0;
- this.nMoment = 1;
- this.nSpeed_x = _n * 5;
- }
- }
- function stand()
- {
- this.mClip._y = this.nY_mClip;
- this.nMoment = 0;
- this.nSpeed_x = 0;
- this.mClip.mArm_0.mClip.gotoAndStop(1);
- this.nDir = Common.vpNum(this.pTarget._x - this._x);
- this._xscale = this.nDir * 100;
- this.mClip.mHead._rotation = this.mClip._rotation = 0;
- this.mClip.mLeg_0._rotation = 0;
- this.mClip.mLeg_1._rotation = 0;
- this.mClip.mLeg_0._x = 5;
- this.mClip.mLeg_1._x = -5;
- }
- function bow(_m, x, y)
- {
- var _loc2_ = {x:x,y:y};
- var _loc3_ = Common.getAngle(Global.GAME.pKnight,this);
- _m.localToGlobal(_loc2_);
- Global.GAME.mClip.globalToLocal(_loc2_);
- 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});
- }
- function fallEnd()
- {
- this.bFall = false;
- this.nSpeed_y = 0;
- this.mClip._y = this.nY_mClip;
- this.setPos_0();
- if(this.bHit)
- {
- this.nMoment = 6;
- this.mClip._rotation = -90;
- }
- else
- {
- this.stand();
- }
- this.mClip.mArm_0.mClip.gotoAndStop(1);
- }
- function beHit(_l, _r)
- {
- this.mClip.mArm_0.mClip.gotoAndStop(1);
- this.nHealth -= 10;
- this.mClip._y = this.nY_mClip;
- var _loc2_ = math.Vector.polar(_l,_r);
- this.nSpeed_x = int(_loc2_.x);
- this.nSpeed_y = int(_loc2_.y);
- if(this.nSpeed_y < 0 || this.nMoment == 6 || this.bFall)
- {
- if(this.bHit)
- {
- if(this.nSpeed_y > -8)
- {
- this.nSpeed_y = -8;
- }
- }
- this.bFall = true;
- this.nMoment = 5;
- }
- else
- {
- this.nMoment = 4;
- this.mClip._rotation = Common.rdm_2(-20,20);
- this.mClip.mHead._rotation = Common.rdm_2(-30,30);
- }
- this.bHit = true;
- this.mClip.mHead.mEye.gotoAndPlay(2);
- this.nTime = 30;
- }
- function ckHit(_m)
- {
- var _loc2_ = {x:0,y:0};
- var _loc3_ = new Object();
- _m.localToGlobal(_loc2_);
- _loc3_.x = Global.GAME.pKnight.vHit.x;
- _loc3_.y = Global.GAME.pKnight.vHit.y;
- Global.GAME.pKnight.localToGlobal(_loc3_);
- var _loc5_ = Common.distance(_loc2_.x,_loc2_.y,_loc3_.x,_loc3_.y);
- if(_loc5_ < _m.nRadius + Global.GAME.pKnight.nRadius)
- {
- Global.GAME.pKnight.beHit();
- _loc2_.x = (_loc2_.x + _loc3_.x) / 2;
- _loc2_.y = (_loc2_.y + _loc3_.y) / 2;
- Global.GAME.pKnight.globalToLocal(_loc2_);
- 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});
- }
- }
- function death()
- {
- this.remove();
- Global.playSound("sdDeath_" + random(8));
- Global.GAME.pKnight.nKill = Global.GAME.pKnight.nKill + 1;
- }
- function movement()
- {
- var _loc2_ = getTimer();
- if(this.bHit)
- {
- switch(this.nMoment)
- {
- case 4:
- if(this.nHealth > 0)
- {
- if(this.nTime <= 0)
- {
- this.nTime = 0;
- this.bHit = false;
- this.stand();
- }
- else
- {
- this.nTime = this.nTime - 1;
- }
- }
- else
- {
- this.death();
- delete this.onEnterFrame;
- this.onEnterFrame = null;
- new Exp(this.mClip,Global.GAME.mClip.mMid);
- }
- break;
- case 5:
- this.mClip._rotation = (- this.nSpeed_y) * 3 - 90;
- break;
- case 6:
- this.nTime = this.nTime - 1;
- if(this.nHealth > 0)
- {
- if(this.nTime <= 0)
- {
- this.bHit = false;
- this.stand();
- }
- else if(this.nTime < 20)
- {
- this.mClip._rotation = (- this.nTime) * 4;
- }
- }
- else
- {
- if(this.mClip._alpha > 99)
- {
- if(!random(3))
- {
- this.nMoment = 4;
- break;
- }
- this.death();
- }
- this.mClip._alpha -= 10;
- if(this.mClip._alpha < 0)
- {
- this.removeMovieClip();
- }
- }
- break;
- case 7:
- }
- }
- else
- {
- switch(this.nMoment)
- {
- case 0:
- this.mClip.mHead._y = - Common.linearCycle(_loc2_,800,2) - 7;
- break;
- case 1:
- this.mClip.mHead._y = - Common.linearCycle(_loc2_,800,2) - 7;
- this.mClip.mLeg_0._rotation = 100 - Common.linearCycle(_loc2_,800,180);
- this.mClip.mLeg_1._rotation = 100 - Common.linearCycle(_loc2_ + 400,800,180);
- this.mClip.mArm_0._rotation = this.mClip.mLeg_0._rotation + 90;
- this.mClip.mArm_1._rotation = this.mClip.mLeg_1._rotation + 90;
- this.mClip.mLeg_0._x = _loc0_ = Common.linearCycle(_loc2_,800,10) - 5;
- this.mClip.mArm_0._x = _loc0_;
- this.mClip.mLeg_1._x = _loc0_ = Common.linearCycle(_loc2_ + 400,800,10) - 5;
- this.mClip.mArm_1._x = _loc0_;
- this.mClip._y = - Common.linearCycle(_loc2_ + 200,400,20) - 10;
- break;
- case 2:
- case 3:
- }
- }
- }
- function moving()
- {
- if(this.nSpeed_x)
- {
- this._x += this.nSpeed_x;
- if(!this.bFall)
- {
- if(this.bHit)
- {
- this.nSpeed_x /= 2;
- this.nSpeed_x = int(this.nSpeed_x);
- }
- this.setPos_0();
- }
- }
- }
- function onEnterFrame()
- {
- if(!Global.GAME.bPause)
- {
- this.ctrl();
- this.falling();
- this.moving();
- this.movement();
- if(this._y > 480)
- {
- this.remove();
- this.removeMovieClip();
- }
- }
- }
- function ctrl()
- {
- if(!this.bHit)
- {
- var _loc2_ = this.pTarget._x - this._x;
- if(Math.abs(_loc2_) > this.nRange_atk)
- {
- if(this.nTime <= 0)
- {
- this.nTime = 0;
- this.walk(Common.vpNum(_loc2_));
- }
- else
- {
- this.nTime -= 10;
- }
- }
- else
- {
- if(this.nTime == 0)
- {
- this.stand();
- this.nTime = 120;
- this.mClip.mArm_0._rotation = 0;
- }
- else if(this.nTime < 100)
- {
- this.mClip.mArm_0.mClip.play();
- }
- this.nTime = this.nTime - 1;
- }
- }
- }
- }
-