home *** CD-ROM | disk | FTP | other *** search
- class Ally_Fighter extends MovieClip
- {
- var gunFlagOne;
- var flagExplode;
- var guns;
- var haltMovie;
- var safetyTurn;
- var numLife;
- var strMiniBubbleName;
- var numSpeed;
- var numFramesToTurn;
- var numAmountToTurn;
- var minFramesToHoldTurning;
- var enemyOff;
- var _damage;
- var _strCreatedBy;
- var _currentTarget;
- var intLastCheckTarget;
- var intFocus;
- var vecFocusOffset;
- var intShootingRange;
- var intResetOffsetCounter;
- var intState;
- var _type;
- function Ally_Fighter()
- {
- super();
- this.gunFlagOne = true;
- this.flagExplode = false;
- this.guns = new Array();
- this.haltMovie = false;
- this.safetyTurn = false;
- this.numLife = 1;
- this.gotoAndPlay(this.numLife);
- this.strMiniBubbleName = "";
- this.numSpeed = 8;
- this.numFramesToTurn = 0;
- this.numAmountToTurn = 0;
- this.minFramesToHoldTurning = 0;
- this.enemyOff = false;
- this._damage = 0;
- this._strCreatedBy = "";
- this._currentTarget = "";
- this.intLastCheckTarget = 0;
- this.intFocus = 2;
- this.vecFocusOffset = new Vector();
- this.intShootingRange = 100;
- this.intResetOffsetCounter = 45;
- this.intState = 3;
- this._type = 10;
- this.guns.push({name:"gun_1",type:1,fireTimerMax:8,fireTimerMin:8,counter:8,speed:10,size:75,damage:1});
- }
- function onEnterFrame()
- {
- if(!this.enemyOff)
- {
- if(this.intState != 2)
- {
- if(this.intState == 3)
- {
- var _loc3_ = this.GetVector2Focus();
- if(_loc3_.GetLength() > this.intShootingRange)
- {
- this._rotation += _loc3_.AngleToAlign(this._rotation,this.numSpeed,2);
- }
- else
- {
- if(this.intLastCheckTarget == 0)
- {
- this._currentTarget = _root.game.GetNearestEnemy(this._x,this._y);
- this.intLastCheckTarget = 20;
- }
- else
- {
- this.intLastCheckTarget = this.intLastCheckTarget - 1;
- }
- if(this._currentTarget == "")
- {
- this.intState = 4;
- }
- if(_root[this._currentTarget]._name == undefined)
- {
- this._currentTarget = _root.game.GetNearestEnemy(this._x,this._y);
- this.intLastCheckTarget = 20;
- if(_root[this._currentTarget]._name == undefined)
- {
- this.intState = 4;
- }
- }
- if(this.intState == 3)
- {
- this.OperateWeapons();
- }
- }
- }
- else if(this.intState == 4)
- {
- _loc3_ = this.GetVector2Focus();
- this._rotation += _loc3_.AngleToAlign(this._rotation,this.numSpeed,2);
- if(_loc3_.GetLength() < this.numSpeed)
- {
- this.Dock();
- }
- }
- }
- this.MoveMe();
- if(this.intResetOffsetCounter == 0)
- {
- this.ResetOffset();
- this.intResetOffsetCounter = 45;
- }
- else
- {
- this.intResetOffsetCounter = this.intResetOffsetCounter - 1;
- }
- }
- }
- function RandNum(minVal, maxVal)
- {
- return Math.round(Math.random() * (maxVal - minVal)) + minVal;
- }
- function SelfDestruct()
- {
- }
- function Dock()
- {
- this.RemoveMiniBubble();
- _root.game.RemoveAlly(this._name);
- this.removeMovieClip();
- }
- function CreateMiniBubble()
- {
- if(this.strMiniBubbleName == "")
- {
- this.strMiniBubbleName = this._name + "_miniBubble";
- _root.miniBubblesLayer_mc.attachMovie("fighter_bubble",this.strMiniBubbleName,this.getDepth());
- var refBubble = eval("_root.miniBubblesLayer_mc." + this.strMiniBubbleName);
- var point = {x:this._x,y:this._y};
- refBubble._parent.globalToLocal(point);
- refBubble._x = point.x;
- refBubble._y = point.y;
- }
- }
- function RemoveMiniBubble()
- {
- if(this.strMiniBubbleName != "")
- {
- var refBubble = eval("_root.miniBubblesLayer_mc." + this.strMiniBubbleName);
- refBubble.removeMovieClip();
- this.strMiniBubbleName = "";
- }
- }
- function MoveMiniBubble()
- {
- if(this.InRange() == true)
- {
- if(this.strMiniBubbleName == "")
- {
- this.CreateMiniBubble();
- }
- }
- else if(this.strMiniBubbleName != "")
- {
- this.RemoveMiniBubble();
- }
- if(this.strMiniBubbleName != "")
- {
- var refBubble = eval("_root.miniBubblesLayer_mc." + this.strMiniBubbleName);
- var point = {x:this._x,y:this._y};
- refBubble._parent.globalToLocal(point);
- refBubble._x = point.x;
- refBubble._y = point.y;
- }
- }
- function OperateWeapons()
- {
- var i = 0;
- while(i < this.guns.length)
- {
- if(this.guns[i].type == 1)
- {
- var ObjRef = eval("this." + this.guns[i].name);
- var point = {x:ObjRef._x,y:ObjRef._y};
- ObjRef.localToGlobal(point);
- var refTarget = _root[this._currentTarget];
- var vecDirection = new Vector();
- vecDirection._x = refTarget._x - point.x;
- vecDirection._y = refTarget._y - point.y;
- if(vecDirection.GetLength() < this.intShootingRange)
- {
- var myRadians = Math.atan2(vecDirection._y,vecDirection._x);
- var myDegrees = 360 * myRadians / 6.283185307179586;
- ObjRef._rotation = myDegrees - this._rotation;
- if(this.guns[i].counter < 1)
- {
- var posVector = new Vector();
- var ObjRefTwo = eval("this." + this.guns[i].name + ".emitter");
- var pointTwo = {x:ObjRefTwo._x,y:ObjRefTwo._y};
- ObjRefTwo.localToGlobal(pointTwo);
- posVector._x = pointTwo.x;
- posVector._y = pointTwo.y;
- _root.game.AvatarFireBullet(posVector,ObjRef._rotation + this._rotation,this.guns[i].speed,this.guns[i].size,this.guns[i].damage);
- this.guns[i].counter = Math.round(Math.random() * (this.guns[i].fireTimerMax - this.guns[i].fireTimerMin)) + this.guns[i].fireTimerMin;
- }
- else
- {
- this.guns[i].counter--;
- }
- }
- }
- i++;
- }
- }
- function ReceiveDamage(amountDamage)
- {
- var _loc3_ = false;
- this.numLife -= amountDamage;
- if(this.numLife < 1)
- {
- _loc3_ = true;
- _root.ReportDeath(this._name);
- this.removeMovieClip();
- }
- else
- {
- this.gotoAndStop(this.numLife);
- }
- return _loc3_;
- }
- function RemoveGun(strName)
- {
- var _loc2_ = 0;
- while(_loc2_ < this.guns.length)
- {
- if(strName == this.guns[_loc2_].name)
- {
- this.guns.splice(_loc2_,1);
- break;
- }
- _loc2_ = _loc2_ + 1;
- }
- }
- function MoveMe()
- {
- var _loc2_ = new Vector();
- _loc2_._x = Math.cos(3.141592653589793 * this._rotation / 180) * this.numSpeed + this._x;
- _loc2_._y = Math.sin(3.141592653589793 * this._rotation / 180) * this.numSpeed + this._y;
- this._x = _loc2_._x;
- this._y = _loc2_._y;
- this.MoveMiniBubble();
- }
- function GetAnglePos()
- {
- var _loc3_ = new Vector();
- _loc3_._x = this._x - _root.bg._x;
- _loc3_._y = this._y - _root.bg._y;
- var _loc4_ = Math.atan2(_loc3_._y,_loc3_._x);
- var _loc5_ = 360 * _loc4_ / 6.283185307179586;
- return _loc5_;
- }
- function InRange()
- {
- return this.GetDistance() > _root.bg.inside._width / 2 - 30;
- }
- function GetDistance()
- {
- var _loc4_ = this._x - _root.bg._x;
- var _loc3_ = this._y - _root.bg._y;
- return Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_);
- }
- function GetDistance2Target()
- {
- var _loc4_ = this._x - _root[this._currentTarget]._x;
- var _loc3_ = this._y - _root[this._currentTarget]._y;
- return Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_);
- }
- function GetVector2Focus()
- {
- var vecReturn = new Vector();
- if(this.intState == 4)
- {
- var gunRef = eval("_root.avatar.gun." + this._strCreatedBy);
- if(gunRef._name == undefined)
- {
- _root.game.Effect_PierceExplosion(this._x,this._y);
- this.Dock();
- }
- else
- {
- var point = {x:gunRef.emitter._x,y:gunRef.emitter._y};
- gunRef.localToGlobal(point);
- vecReturn._x = point.x - this._x;
- vecReturn._y = point.y - this._y;
- }
- }
- else if(this.intFocus != 1)
- {
- vecReturn._x = _root._xmouse + this.vecFocusOffset._x - this._x;
- vecReturn._y = _root._ymouse + this.vecFocusOffset._y - this._y;
- }
- return vecReturn;
- }
- function ResetOffset()
- {
- this.vecFocusOffset._x = this.RandNum(-25,25);
- this.vecFocusOffset._y = this.RandNum(-25,25);
- }
- function AboutToExit()
- {
- var _loc5_ = false;
- var _loc6_ = Math.cos(3.141592653589793 * this._rotation / 180) * (this._width + 30 * this.numSpeed) + this._x;
- var _loc8_ = Math.sin(3.141592653589793 * this._rotation / 180) * (this._width + 30 * this.numSpeed) + this._y;
- var _loc7_ = 200;
- var _loc4_ = _loc6_ - _root._xmouse;
- var _loc3_ = _loc8_ - _root._ymouse;
- if(Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_) > _loc7_)
- {
- _loc5_ = true;
- }
- return _loc5_;
- }
- function TurnOff()
- {
- this.enemyOff = true;
- }
- function TurnOn()
- {
- this.enemyOff = false;
- }
- }
-