home *** CD-ROM | disk | FTP | other *** search
- class Enemy extends LRG.LRGMovieClip
- {
- var m_fPointValue;
- var m_bExploding;
- var m_kHidingBehindBarrier;
- var m_fTimesWaited;
- var m_kCollision;
- var m_fRadius;
- var m_fLastUpdateTime;
- var m_fRotation;
- var m_fDestinationX;
- var m_fDestinationY;
- var m_fSpeed;
- var m_fType;
- function Enemy()
- {
- super();
- }
- function init()
- {
- super.init();
- this.setClock(_global.getGameTimer());
- this.m_fPointValue = 0;
- this.m_bExploding = false;
- this.m_kHidingBehindBarrier = null;
- this.m_fTimesWaited = 0;
- }
- function onAdd()
- {
- if(Settings(_global.getSettings()).getSetting("HIDE_BOUNDARIES"))
- {
- this.m_kCollision._visible = false;
- }
- this.m_fRadius = (this.m_kCollision._width + this.m_kCollision._height) / 4;
- this.m_fLastUpdateTime = this.getClipTime();
- this.playAnimation("STAND",60,1,14,true,1);
- var _loc4_ = _global.g_kApplication.m_kGameScreen;
- var _loc3_ = {x:_loc4_.getPlayer()._x,y:_loc4_.getPlayer()._y};
- this.m_fRotation = Math.atan2(_loc3_.y - this._y,_loc3_.x - this._x) / 3.141592653589793 * 180;
- this._rotation = this.m_fRotation;
- _loc4_.localToGlobal(_loc3_);
- this._parent.globalToLocal(_loc3_);
- this.setDestination(_loc3_.x,_loc3_.y,true);
- }
- function onRemove()
- {
- this.stopAction("MOVE_TO_DESTINATION",false);
- this.stopAction("STAND",false);
- this.stopAction("WALK",false);
- this.stopAction("UNHIDE",false);
- }
- function setDestination(fDestX, fDestY, bMeander)
- {
- if(bMeander && !this.m_kHidingBehindBarrier)
- {
- var _loc9_ = _global.LRG.Utils.Vector2D.normalize(fDestX - this._x,fDestY - this._y);
- if(this.m_kHidingBehindBarrier = this.checkBarriers(this._x + _loc9_.x * 25,this._y + _loc9_.y * 25))
- {
- var _loc8_ = {x:this.m_kHidingBehindBarrier.m_kEnemyStandPoint._x,y:this.m_kHidingBehindBarrier.m_kEnemyStandPoint._y};
- this.m_kHidingBehindBarrier.localToGlobal(_loc8_);
- this._parent.globalToLocal(_loc8_);
- this.hideBehindBarrier();
- return undefined;
- }
- var _loc5_ = Math.atan2(fDestY - this._y,fDestX - this._x) / 3.141592653589793 * 180;
- if(Math.round(_loc5_) == Math.round(this.m_fRotation))
- {
- this.m_fRotation += Math.random() * 60 - 30;
- }
- else
- {
- this.m_fRotation = _loc5_;
- }
- var _loc7_ = this.m_fRotation / 180 * 3.141592653589793;
- var _loc6_ = Math.random() * 30 + 20;
- this.m_fDestinationX = this._x + Math.cos(_loc7_) * _loc6_;
- this.m_fDestinationY = this._y + Math.sin(_loc7_) * _loc6_;
- }
- else
- {
- this.m_fDestinationX = fDestX;
- this.m_fDestinationY = fDestY;
- this.m_fRotation = Math.atan2(this.m_fDestinationY - this._y,this.m_fDestinationX - this._x) / 3.141592653589793 * 180;
- }
- var _loc14_ = undefined;
- if(this.m_fTimesWaited <= 5 && (_loc14_ = FullmetalGame(_global.g_kApplication.m_kGameScreen).getEnemyManager().checkCollision({x:this._x,y:this._y},{x:this.m_fDestinationX,y:this.m_fDestinationY},this)))
- {
- this.m_fTimesWaited = this.m_fTimesWaited + 1;
- var _loc4_ = new Object();
- _loc4_.m_sName = "WAIT_TO_MOVE";
- _loc4_.m_fTotalActionTime = Math.random() * 5 + 0.5;
- var _loc12_ = new LRG.LRGWaitAction(_loc4_);
- this.addAction(_loc12_);
- this.startAction("WAIT_TO_MOVE",null,true);
- this.playAnimation("STAND",60,1,14,true,1);
- return undefined;
- }
- this.m_fTimesWaited = 0;
- var _loc3_ = new Object();
- _loc3_.m_sName = "MOVE_TO_DESTINATION";
- _loc3_.m_fFPS = 45;
- _loc3_.m_fSpeed = this.m_fSpeed;
- _loc3_.m_kGoal = {x:this.m_fDestinationX,y:this.m_fDestinationY};
- _loc3_.m_fGoalRotation = this.m_fRotation;
- var _loc13_ = new LRG.LRGMoveAction(_loc3_);
- this.addAction(_loc13_);
- this.startAction("MOVE_TO_DESTINATION",null,true);
- if(this.getActiveActions().getIndex("WALK") == -1)
- {
- this.playAnimation("WALK",30,15,24,true,1);
- }
- }
- function checkBarriers(fXPos, fYPos)
- {
- var _loc4_ = {x:fXPos,y:fYPos};
- this._parent.localToGlobal(_loc4_);
- var _loc3_ = _global.g_kApplication.m_kGameScreen;
- if(_loc3_.m_kBarrier1.isExplodable() && _loc3_.m_kBarrier1.hitTest(_loc4_.x,_loc4_.y,true))
- {
- return _loc3_.m_kBarrier1;
- }
- if(_loc3_.m_kBarrier2.isExplodable() && _loc3_.m_kBarrier2.hitTest(_loc4_.x,_loc4_.y,true))
- {
- return _loc3_.m_kBarrier2;
- }
- if(_loc3_.m_kBarrier3.isExplodable() && _loc3_.m_kBarrier3.hitTest(_loc4_.x,_loc4_.y,true))
- {
- return _loc3_.m_kBarrier3;
- }
- if(_loc3_.m_kBarrier4.isExplodable() && _loc3_.m_kBarrier4.hitTest(_loc4_.x,_loc4_.y,true))
- {
- return _loc3_.m_kBarrier4;
- }
- if(_loc3_.m_kBarrier5.isExplodable() && _loc3_.m_kBarrier5.hitTest(_loc4_.x,_loc4_.y,true))
- {
- return _loc3_.m_kBarrier5;
- }
- if(_loc3_.m_kBarrier6.isExplodable() && _loc3_.m_kBarrier6.hitTest(_loc4_.x,_loc4_.y,true))
- {
- return _loc3_.m_kBarrier6;
- }
- if(_loc3_.m_kBarrier7.isExplodable() && _loc3_.m_kBarrier7.hitTest(_loc4_.x,_loc4_.y,true))
- {
- return _loc3_.m_kBarrier7;
- }
- if(_loc3_.m_kBarrier8.isExplodable() && _loc3_.m_kBarrier8.hitTest(_loc4_.x,_loc4_.y,true))
- {
- return _loc3_.m_kBarrier8;
- }
- }
- function hideBehindBarrier()
- {
- this.stopAction("WALK",false);
- this.playAnimation("STAND",3,1,14,true,1);
- var _loc3_ = new Object();
- _loc3_.m_sName = "UNHIDE";
- _loc3_.m_fTotalActionTime = Math.random() * Settings(_global.getSettings()).getSetting("ENEMY_MAX_HIDE_TIME") + Settings(_global.getSettings()).getSetting("ENEMY_MIN_HIDE_TIME");
- _loc3_.m_kCallback = this.unhideCallback;
- var _loc4_ = new LRG.LRGDelayedCallbackAction(_loc3_);
- this.addAction(_loc4_);
- this.startAction("UNHIDE",null,true);
- }
- function unhideCallback()
- {
- var _loc4_ = Math.floor(Math.random() * 2) + 1;
- var _loc3_ = this.m_kHidingBehindBarrier["m_kWaypoint" + _loc4_];
- var _loc2_ = {x:_loc3_._x,y:_loc3_._y};
- this.m_kHidingBehindBarrier.localToGlobal(_loc2_);
- this._parent.globalToLocal(_loc2_);
- this.m_kHidingBehindBarrier = null;
- this.setDestination(_loc2_.x,_loc2_.y,false);
- }
- function getDestinationX()
- {
- return this.m_fDestinationX;
- }
- function getDestinationY()
- {
- return this.m_fDestinationY;
- }
- function isDestinationReached()
- {
- return this.getActiveActions().getIndex("MOVE_TO_DESTINATION") != -1;
- }
- function setSpeed(fSpeed)
- {
- this.m_fSpeed = fSpeed;
- }
- function getSpeed()
- {
- return this.m_fSpeed;
- }
- function setType(fType)
- {
- this.m_fType = fType;
- }
- function getType()
- {
- return this.m_fType;
- }
- function getRadius()
- {
- return this.m_fRadius;
- }
- function setPointValue(fPointValue)
- {
- this.m_fPointValue = fPointValue;
- }
- function getPointValue()
- {
- return this.m_fPointValue;
- }
- function explode(fNumberInChain)
- {
- if(fNumberInChain > 1)
- {
- FullmetalGame(_global.g_kApplication.m_kGameScreen).addBonusAnimation(this._x,this._y);
- }
- this.m_bExploding = true;
- PlayerState(_global.getPlayerState()).setScore(PlayerState(_global.getPlayerState()).getScore() + this.getPointValue() * fNumberInChain);
- var _loc3_ = {x:this._x,y:this._y};
- this._parent.localToGlobal(_loc3_);
- var _loc4_ = _loc3_.x / 3 - 100;
- _global.playSound("fma_npc_dies" + this.m_fType + ".wav",1,this,_loc4_);
- this.stopAction("MOVE_TO_DESTINATION",false);
- this.stopAction("STAND",false);
- this.stopAction("WALK",false);
- this.stopAction("UNHIDE",false);
- this.playAnimation("EXPLODE",30,25,43,false,1);
- }
- function isExploding()
- {
- return this.m_bExploding;
- }
- function onActionCompleted(sActionKey)
- {
- if(sActionKey == "EXPLODE")
- {
- this.m_bExploding = false;
- FullmetalGame(_global.g_kApplication.m_kGameScreen).getEnemyManager().onRequestRemoveEnemy(this);
- FullmetalGame(_global.g_kApplication.m_kGameScreen).onEnemyDied();
- }
- else if(sActionKey == "MOVE_TO_DESTINATION")
- {
- if(this.m_kHidingBehindBarrier)
- {
- this.hideBehindBarrier();
- return undefined;
- }
- var _loc5_ = _global.g_kApplication.m_kGameScreen;
- var _loc4_ = {x:this._x,y:this._y};
- this._parent.localToGlobal(_loc4_);
- if(_loc5_.isSmartBomb() && _loc5_.m_kAlchemySymbol.m_kCollision.hitTest(_loc4_.x,_loc4_.y,true))
- {
- this.explode(1);
- return undefined;
- }
- var _loc3_ = {x:_loc5_.getPlayer()._x,y:_loc5_.getPlayer()._y};
- _loc5_.localToGlobal(_loc3_);
- this._parent.globalToLocal(_loc3_);
- if(this.hitTest(_loc3_.x,_loc3_.y,true))
- {
- if(!_loc5_.getPlayer().isFiring())
- {
- _loc5_.onPlayerDied();
- return undefined;
- }
- this.setDestination(this._x,this._y,true);
- return undefined;
- }
- this.setDestination(_loc3_.x,_loc3_.y,true);
- }
- else if(sActionKey == "WAIT_TO_MOVE")
- {
- if(this.m_bExploding)
- {
- return undefined;
- }
- if(this.m_kHidingBehindBarrier)
- {
- this.unhideCallback();
- }
- else
- {
- _loc5_ = _global.g_kApplication.m_kGameScreen;
- _loc3_ = {x:_loc5_.getPlayer()._x,y:_loc5_.getPlayer()._y};
- _loc5_.localToGlobal(_loc3_);
- this._parent.globalToLocal(_loc3_);
- this.setDestination(_loc3_.x,_loc3_.y,true);
- }
- }
- }
- }
-