home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / flameout.swf / scripts / __Packages / Enemy.as < prev    next >
Encoding:
Text File  |  2006-06-13  |  10.2 KB  |  294 lines

  1. class Enemy extends LRG.LRGMovieClip
  2. {
  3.    var m_fPointValue;
  4.    var m_bExploding;
  5.    var m_kHidingBehindBarrier;
  6.    var m_fTimesWaited;
  7.    var m_kCollision;
  8.    var m_fRadius;
  9.    var m_fLastUpdateTime;
  10.    var m_fRotation;
  11.    var m_fDestinationX;
  12.    var m_fDestinationY;
  13.    var m_fSpeed;
  14.    var m_fType;
  15.    function Enemy()
  16.    {
  17.       super();
  18.    }
  19.    function init()
  20.    {
  21.       super.init();
  22.       this.setClock(_global.getGameTimer());
  23.       this.m_fPointValue = 0;
  24.       this.m_bExploding = false;
  25.       this.m_kHidingBehindBarrier = null;
  26.       this.m_fTimesWaited = 0;
  27.    }
  28.    function onAdd()
  29.    {
  30.       if(Settings(_global.getSettings()).getSetting("HIDE_BOUNDARIES"))
  31.       {
  32.          this.m_kCollision._visible = false;
  33.       }
  34.       this.m_fRadius = (this.m_kCollision._width + this.m_kCollision._height) / 4;
  35.       this.m_fLastUpdateTime = this.getClipTime();
  36.       this.playAnimation("STAND",60,1,14,true,1);
  37.       var _loc4_ = _global.g_kApplication.m_kGameScreen;
  38.       var _loc3_ = {x:_loc4_.getPlayer()._x,y:_loc4_.getPlayer()._y};
  39.       this.m_fRotation = Math.atan2(_loc3_.y - this._y,_loc3_.x - this._x) / 3.141592653589793 * 180;
  40.       this._rotation = this.m_fRotation;
  41.       _loc4_.localToGlobal(_loc3_);
  42.       this._parent.globalToLocal(_loc3_);
  43.       this.setDestination(_loc3_.x,_loc3_.y,true);
  44.    }
  45.    function onRemove()
  46.    {
  47.       this.stopAction("MOVE_TO_DESTINATION",false);
  48.       this.stopAction("STAND",false);
  49.       this.stopAction("WALK",false);
  50.       this.stopAction("UNHIDE",false);
  51.    }
  52.    function setDestination(fDestX, fDestY, bMeander)
  53.    {
  54.       if(bMeander && !this.m_kHidingBehindBarrier)
  55.       {
  56.          var _loc9_ = _global.LRG.Utils.Vector2D.normalize(fDestX - this._x,fDestY - this._y);
  57.          if(this.m_kHidingBehindBarrier = this.checkBarriers(this._x + _loc9_.x * 25,this._y + _loc9_.y * 25))
  58.          {
  59.             var _loc8_ = {x:this.m_kHidingBehindBarrier.m_kEnemyStandPoint._x,y:this.m_kHidingBehindBarrier.m_kEnemyStandPoint._y};
  60.             this.m_kHidingBehindBarrier.localToGlobal(_loc8_);
  61.             this._parent.globalToLocal(_loc8_);
  62.             this.hideBehindBarrier();
  63.             return undefined;
  64.          }
  65.          var _loc5_ = Math.atan2(fDestY - this._y,fDestX - this._x) / 3.141592653589793 * 180;
  66.          if(Math.round(_loc5_) == Math.round(this.m_fRotation))
  67.          {
  68.             this.m_fRotation += Math.random() * 60 - 30;
  69.          }
  70.          else
  71.          {
  72.             this.m_fRotation = _loc5_;
  73.          }
  74.          var _loc7_ = this.m_fRotation / 180 * 3.141592653589793;
  75.          var _loc6_ = Math.random() * 30 + 20;
  76.          this.m_fDestinationX = this._x + Math.cos(_loc7_) * _loc6_;
  77.          this.m_fDestinationY = this._y + Math.sin(_loc7_) * _loc6_;
  78.       }
  79.       else
  80.       {
  81.          this.m_fDestinationX = fDestX;
  82.          this.m_fDestinationY = fDestY;
  83.          this.m_fRotation = Math.atan2(this.m_fDestinationY - this._y,this.m_fDestinationX - this._x) / 3.141592653589793 * 180;
  84.       }
  85.       var _loc14_ = undefined;
  86.       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)))
  87.       {
  88.          this.m_fTimesWaited = this.m_fTimesWaited + 1;
  89.          var _loc4_ = new Object();
  90.          _loc4_.m_sName = "WAIT_TO_MOVE";
  91.          _loc4_.m_fTotalActionTime = Math.random() * 5 + 0.5;
  92.          var _loc12_ = new LRG.LRGWaitAction(_loc4_);
  93.          this.addAction(_loc12_);
  94.          this.startAction("WAIT_TO_MOVE",null,true);
  95.          this.playAnimation("STAND",60,1,14,true,1);
  96.          return undefined;
  97.       }
  98.       this.m_fTimesWaited = 0;
  99.       var _loc3_ = new Object();
  100.       _loc3_.m_sName = "MOVE_TO_DESTINATION";
  101.       _loc3_.m_fFPS = 45;
  102.       _loc3_.m_fSpeed = this.m_fSpeed;
  103.       _loc3_.m_kGoal = {x:this.m_fDestinationX,y:this.m_fDestinationY};
  104.       _loc3_.m_fGoalRotation = this.m_fRotation;
  105.       var _loc13_ = new LRG.LRGMoveAction(_loc3_);
  106.       this.addAction(_loc13_);
  107.       this.startAction("MOVE_TO_DESTINATION",null,true);
  108.       if(this.getActiveActions().getIndex("WALK") == -1)
  109.       {
  110.          this.playAnimation("WALK",30,15,24,true,1);
  111.       }
  112.    }
  113.    function checkBarriers(fXPos, fYPos)
  114.    {
  115.       var _loc4_ = {x:fXPos,y:fYPos};
  116.       this._parent.localToGlobal(_loc4_);
  117.       var _loc3_ = _global.g_kApplication.m_kGameScreen;
  118.       if(_loc3_.m_kBarrier1.isExplodable() && _loc3_.m_kBarrier1.hitTest(_loc4_.x,_loc4_.y,true))
  119.       {
  120.          return _loc3_.m_kBarrier1;
  121.       }
  122.       if(_loc3_.m_kBarrier2.isExplodable() && _loc3_.m_kBarrier2.hitTest(_loc4_.x,_loc4_.y,true))
  123.       {
  124.          return _loc3_.m_kBarrier2;
  125.       }
  126.       if(_loc3_.m_kBarrier3.isExplodable() && _loc3_.m_kBarrier3.hitTest(_loc4_.x,_loc4_.y,true))
  127.       {
  128.          return _loc3_.m_kBarrier3;
  129.       }
  130.       if(_loc3_.m_kBarrier4.isExplodable() && _loc3_.m_kBarrier4.hitTest(_loc4_.x,_loc4_.y,true))
  131.       {
  132.          return _loc3_.m_kBarrier4;
  133.       }
  134.       if(_loc3_.m_kBarrier5.isExplodable() && _loc3_.m_kBarrier5.hitTest(_loc4_.x,_loc4_.y,true))
  135.       {
  136.          return _loc3_.m_kBarrier5;
  137.       }
  138.       if(_loc3_.m_kBarrier6.isExplodable() && _loc3_.m_kBarrier6.hitTest(_loc4_.x,_loc4_.y,true))
  139.       {
  140.          return _loc3_.m_kBarrier6;
  141.       }
  142.       if(_loc3_.m_kBarrier7.isExplodable() && _loc3_.m_kBarrier7.hitTest(_loc4_.x,_loc4_.y,true))
  143.       {
  144.          return _loc3_.m_kBarrier7;
  145.       }
  146.       if(_loc3_.m_kBarrier8.isExplodable() && _loc3_.m_kBarrier8.hitTest(_loc4_.x,_loc4_.y,true))
  147.       {
  148.          return _loc3_.m_kBarrier8;
  149.       }
  150.    }
  151.    function hideBehindBarrier()
  152.    {
  153.       this.stopAction("WALK",false);
  154.       this.playAnimation("STAND",3,1,14,true,1);
  155.       var _loc3_ = new Object();
  156.       _loc3_.m_sName = "UNHIDE";
  157.       _loc3_.m_fTotalActionTime = Math.random() * Settings(_global.getSettings()).getSetting("ENEMY_MAX_HIDE_TIME") + Settings(_global.getSettings()).getSetting("ENEMY_MIN_HIDE_TIME");
  158.       _loc3_.m_kCallback = this.unhideCallback;
  159.       var _loc4_ = new LRG.LRGDelayedCallbackAction(_loc3_);
  160.       this.addAction(_loc4_);
  161.       this.startAction("UNHIDE",null,true);
  162.    }
  163.    function unhideCallback()
  164.    {
  165.       var _loc4_ = Math.floor(Math.random() * 2) + 1;
  166.       var _loc3_ = this.m_kHidingBehindBarrier["m_kWaypoint" + _loc4_];
  167.       var _loc2_ = {x:_loc3_._x,y:_loc3_._y};
  168.       this.m_kHidingBehindBarrier.localToGlobal(_loc2_);
  169.       this._parent.globalToLocal(_loc2_);
  170.       this.m_kHidingBehindBarrier = null;
  171.       this.setDestination(_loc2_.x,_loc2_.y,false);
  172.    }
  173.    function getDestinationX()
  174.    {
  175.       return this.m_fDestinationX;
  176.    }
  177.    function getDestinationY()
  178.    {
  179.       return this.m_fDestinationY;
  180.    }
  181.    function isDestinationReached()
  182.    {
  183.       return this.getActiveActions().getIndex("MOVE_TO_DESTINATION") != -1;
  184.    }
  185.    function setSpeed(fSpeed)
  186.    {
  187.       this.m_fSpeed = fSpeed;
  188.    }
  189.    function getSpeed()
  190.    {
  191.       return this.m_fSpeed;
  192.    }
  193.    function setType(fType)
  194.    {
  195.       this.m_fType = fType;
  196.    }
  197.    function getType()
  198.    {
  199.       return this.m_fType;
  200.    }
  201.    function getRadius()
  202.    {
  203.       return this.m_fRadius;
  204.    }
  205.    function setPointValue(fPointValue)
  206.    {
  207.       this.m_fPointValue = fPointValue;
  208.    }
  209.    function getPointValue()
  210.    {
  211.       return this.m_fPointValue;
  212.    }
  213.    function explode(fNumberInChain)
  214.    {
  215.       if(fNumberInChain > 1)
  216.       {
  217.          FullmetalGame(_global.g_kApplication.m_kGameScreen).addBonusAnimation(this._x,this._y);
  218.       }
  219.       this.m_bExploding = true;
  220.       PlayerState(_global.getPlayerState()).setScore(PlayerState(_global.getPlayerState()).getScore() + this.getPointValue() * fNumberInChain);
  221.       var _loc3_ = {x:this._x,y:this._y};
  222.       this._parent.localToGlobal(_loc3_);
  223.       var _loc4_ = _loc3_.x / 3 - 100;
  224.       _global.playSound("fma_npc_dies" + this.m_fType + ".wav",1,this,_loc4_);
  225.       this.stopAction("MOVE_TO_DESTINATION",false);
  226.       this.stopAction("STAND",false);
  227.       this.stopAction("WALK",false);
  228.       this.stopAction("UNHIDE",false);
  229.       this.playAnimation("EXPLODE",30,25,43,false,1);
  230.    }
  231.    function isExploding()
  232.    {
  233.       return this.m_bExploding;
  234.    }
  235.    function onActionCompleted(sActionKey)
  236.    {
  237.       if(sActionKey == "EXPLODE")
  238.       {
  239.          this.m_bExploding = false;
  240.          FullmetalGame(_global.g_kApplication.m_kGameScreen).getEnemyManager().onRequestRemoveEnemy(this);
  241.          FullmetalGame(_global.g_kApplication.m_kGameScreen).onEnemyDied();
  242.       }
  243.       else if(sActionKey == "MOVE_TO_DESTINATION")
  244.       {
  245.          if(this.m_kHidingBehindBarrier)
  246.          {
  247.             this.hideBehindBarrier();
  248.             return undefined;
  249.          }
  250.          var _loc5_ = _global.g_kApplication.m_kGameScreen;
  251.          var _loc4_ = {x:this._x,y:this._y};
  252.          this._parent.localToGlobal(_loc4_);
  253.          if(_loc5_.isSmartBomb() && _loc5_.m_kAlchemySymbol.m_kCollision.hitTest(_loc4_.x,_loc4_.y,true))
  254.          {
  255.             this.explode(1);
  256.             return undefined;
  257.          }
  258.          var _loc3_ = {x:_loc5_.getPlayer()._x,y:_loc5_.getPlayer()._y};
  259.          _loc5_.localToGlobal(_loc3_);
  260.          this._parent.globalToLocal(_loc3_);
  261.          if(this.hitTest(_loc3_.x,_loc3_.y,true))
  262.          {
  263.             if(!_loc5_.getPlayer().isFiring())
  264.             {
  265.                _loc5_.onPlayerDied();
  266.                return undefined;
  267.             }
  268.             this.setDestination(this._x,this._y,true);
  269.             return undefined;
  270.          }
  271.          this.setDestination(_loc3_.x,_loc3_.y,true);
  272.       }
  273.       else if(sActionKey == "WAIT_TO_MOVE")
  274.       {
  275.          if(this.m_bExploding)
  276.          {
  277.             return undefined;
  278.          }
  279.          if(this.m_kHidingBehindBarrier)
  280.          {
  281.             this.unhideCallback();
  282.          }
  283.          else
  284.          {
  285.             _loc5_ = _global.g_kApplication.m_kGameScreen;
  286.             _loc3_ = {x:_loc5_.getPlayer()._x,y:_loc5_.getPlayer()._y};
  287.             _loc5_.localToGlobal(_loc3_);
  288.             this._parent.globalToLocal(_loc3_);
  289.             this.setDestination(_loc3_.x,_loc3_.y,true);
  290.          }
  291.       }
  292.    }
  293. }
  294.