home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 145 / MOBICLIC145.ISO / pc / DATA / DSS145 / DSS145_12 / DSS145_12.swf / scripts / dss145_12 / EnemiesAttackManager.as < prev    next >
Text File  |  2012-07-19  |  9KB  |  272 lines

  1. package dss145_12
  2. {
  3.    import flash.display.MovieClip;
  4.    import flash.geom.Point;
  5.    import flash.utils.getTimer;
  6.    
  7.    public class EnemiesAttackManager
  8.    {
  9.        
  10.       
  11.       public var _enemies:Vector.<Enemy>;
  12.       
  13.       public var sequences:Vector.<AttackSequence>;
  14.       
  15.       public var sequence2:Array;
  16.       
  17.       public var lastAttack:Object = null;
  18.       
  19.       public var decor:Decor;
  20.       
  21.       public var startTime:int = 0;
  22.       
  23.       private var models:MovieClip;
  24.       
  25.       private var marks:MovieClip;
  26.       
  27.       private var _totalTime:int = 0;
  28.       
  29.       private var perso:Perso;
  30.       
  31.       private var sequenceTotalTime:Number = 20000;
  32.       
  33.       private var startRelTime:int = 0;
  34.       
  35.       private var laveIntervalTime:int = 3000;
  36.       
  37.       private var level:int = 0;
  38.       
  39.       private var laveIntervals:Array;
  40.       
  41.       public function EnemiesAttackManager(param1:Decor, param2:Perso)
  42.       {
  43.          var _loc3_:AttackSequence = null;
  44.          this._enemies = new Vector.<Enemy>();
  45.          this.sequences = new Vector.<AttackSequence>();
  46.          this.sequence2 = [];
  47.          this.laveIntervals = [10000,7500,6000,5000,4000,3000,2500,2000];
  48.          super();
  49.          this.decor = param1;
  50.          this.perso = param2;
  51.          this.models = param1.CLIP_CONTAINER;
  52.          this.marks = param1.CLIP_CONTAINER;
  53.          this.laveIntervalTime = this.laveIntervals[0];
  54.          _loc3_ = new AttackSequence();
  55.          _loc3_.add({
  56.             "time":3000 + Math.random() * 1000,
  57.             "type":"FEU",
  58.             "repere":this.marks.FEU_REP_01,
  59.             "speedX":-2,
  60.             "speedY":0
  61.          });
  62.          _loc3_.add({
  63.             "time":8000,
  64.             "type":"END"
  65.          });
  66.          this.sequences.push(_loc3_);
  67.          _loc3_ = new AttackSequence();
  68.          _loc3_.add({
  69.             "time":3000 + Math.random() * 1000,
  70.             "type":"FEU",
  71.             "repere":this.marks.FEU_REP_02,
  72.             "speedX":2,
  73.             "speedY":0
  74.          });
  75.          _loc3_.add({
  76.             "time":12000,
  77.             "type":"END"
  78.          });
  79.          this.sequences.push(_loc3_);
  80.          _loc3_ = new AttackSequence();
  81.          _loc3_.add({
  82.             "time":4000 + Math.random() * 1000,
  83.             "type":"FEU",
  84.             "repere":this.marks.FEU_REP_02,
  85.             "speedX":-2,
  86.             "speedY":0
  87.          });
  88.          _loc3_.add({
  89.             "time":12000,
  90.             "type":"END"
  91.          });
  92.          this.sequences.push(_loc3_);
  93.          _loc3_ = new AttackSequence();
  94.          _loc3_.add({
  95.             "time":3000 + Math.random() * 1000,
  96.             "type":"FEU",
  97.             "repere":this.marks.FEU_REP_04,
  98.             "speedX":3,
  99.             "speedY":0
  100.          });
  101.          _loc3_.add({
  102.             "time":7000,
  103.             "type":"FEU",
  104.             "repere":this.marks.FEU_REP_05,
  105.             "speedX":-3,
  106.             "speedY":0
  107.          });
  108.          _loc3_.add({
  109.             "time":10000,
  110.             "type":"END"
  111.          });
  112.          this.sequences.push(_loc3_);
  113.          _loc3_ = new AttackSequence();
  114.          _loc3_.add({
  115.             "time":3000 + Math.random() * 1000,
  116.             "type":"FEU",
  117.             "repere":this.marks.FEU_REP_03,
  118.             "speedX":3,
  119.             "speedY":0
  120.          });
  121.          _loc3_.add({
  122.             "time":10000,
  123.             "type":"END"
  124.          });
  125.          this.sequences.push(_loc3_);
  126.       }
  127.       
  128.       public function update(param1:int) : void
  129.       {
  130.          var _loc3_:int = 0;
  131.          var _loc4_:AttackSequence = null;
  132.          param1 -= this.startTime;
  133.          var _loc2_:int = 0;
  134.          while(_loc2_ < this.sequences.length)
  135.          {
  136.             param1 %= this.sequences[_loc2_].attacks[this.sequences[_loc2_].attacks.length - 1].time;
  137.             if(param1 < this.sequences[_loc2_].timeActual)
  138.             {
  139.                this.sequences[_loc2_].reset();
  140.             }
  141.             this.sequences[_loc2_].timeActual = param1;
  142.             _loc3_ = 0;
  143.             while(_loc3_ < this.sequences[_loc2_].attacks.length)
  144.             {
  145.                if(this.sequences[_loc2_].attacks[_loc3_].done != true && this.sequences[_loc2_].attacks[_loc3_].time <= param1)
  146.                {
  147.                   this.launchAttack(this.sequences[_loc2_].attacks[_loc3_]);
  148.                }
  149.                _loc3_++;
  150.             }
  151.             _loc2_++;
  152.          }
  153.          if(this.laveIntervalTime != 0 && getTimer() - this.startRelTime > this.laveIntervalTime)
  154.          {
  155.             this.startRelTime = getTimer();
  156.             (_loc4_ = new AttackSequence()).add({
  157.                "time":0,
  158.                "type":"LAVE",
  159.                "repere":this.marks.LAVE_REP_10,
  160.                "speedX":0,
  161.                "speedY":3
  162.             });
  163.             this.launchAttack(_loc4_.attacks[0]);
  164.          }
  165.          if(this.decor.getCurrentLevel(this.perso.y) != this.level)
  166.          {
  167.             this.level = this.decor.getCurrentLevel(this.perso.y);
  168.             this.laveIntervalTime = this.laveIntervals[this.level] + (Math.random() * 1000 - 500);
  169.          }
  170.          this.enemiesUpdate();
  171.       }
  172.       
  173.       public function reset(param1:Object) : void
  174.       {
  175.          var _loc2_:int = 0;
  176.          while(_loc2_ < param1.attacks.length)
  177.          {
  178.             if(param1.attacks[_loc2_].type != "END")
  179.             {
  180.                param1.attacks[_loc2_].done = false;
  181.             }
  182.             _loc2_++;
  183.          }
  184.       }
  185.       
  186.       private function launchAttack(param1:Object) : void
  187.       {
  188.          param1.done = true;
  189.          var _loc2_:Enemy = new Enemy(this.decor,this.models.getChildByName(param1.type) as MovieClip);
  190.          _loc2_.type = param1.type;
  191.          _loc2_.anim.gotoAndPlay(1);
  192.          _loc2_.x = param1.startPoint.x;
  193.          _loc2_.y = param1.startPoint.y;
  194.          _loc2_.speedX = param1.speedX;
  195.          _loc2_.speedY = param1.speedY;
  196.          if(_loc2_.speedX > 0)
  197.          {
  198.             _loc2_.scaleX *= -1;
  199.          }
  200.          _loc2_.attackParams = param1;
  201.          this._enemies.push(_loc2_);
  202.       }
  203.       
  204.       public function detectCollision(param1:Perso) : Enemy
  205.       {
  206.          var _loc2_:Point = null;
  207.          var _loc3_:int = 0;
  208.          while(_loc3_ < this._enemies.length)
  209.          {
  210.             if(this._enemies[_loc3_].type == "LAVE")
  211.             {
  212.                _loc2_ = this._enemies[_loc3_].anim.parent.localToGlobal(new Point(this._enemies[_loc3_].anim.x + this._enemies[_loc3_].anim.width / 2,this._enemies[_loc3_].anim.y + this._enemies[_loc3_].anim.height / 2));
  213.                if(param1.clip.STATE.STATE2.hasOwnProperty("HIT_AREA") && param1.clip.STATE.STATE2.HIT_AREA.hitTestPoint(_loc2_.x,_loc2_.y,true))
  214.                {
  215.                   return this._enemies[_loc3_];
  216.                }
  217.             }
  218.             else
  219.             {
  220.                _loc2_ = this._enemies[_loc3_].anim.parent.localToGlobal(new Point(this._enemies[_loc3_].anim.x,this._enemies[_loc3_].anim.y));
  221.                if(param1.clip.STATE.STATE2.hasOwnProperty("HIT_AREA") && param1.clip.STATE.STATE2.HIT_AREA.hitTestPoint(_loc2_.x,_loc2_.y,true))
  222.                {
  223.                   return this._enemies[_loc3_];
  224.                }
  225.             }
  226.             _loc3_++;
  227.          }
  228.          return null;
  229.       }
  230.       
  231.       public function enemiesUpdate() : void
  232.       {
  233.          var _loc1_:int = 0;
  234.          while(_loc1_ < this._enemies.length)
  235.          {
  236.             this._enemies[_loc1_].move();
  237.             this._enemies[_loc1_].redraw();
  238.             if(this._enemies[_loc1_].speedX > 0 && this._enemies[_loc1_].x >= this._enemies[_loc1_].attackParams.endPoint.x || this._enemies[_loc1_].speedX < 0 && this._enemies[_loc1_].x <= this._enemies[_loc1_].attackParams.endPoint.x)
  239.             {
  240.                this.enemyRemove(this._enemies[_loc1_]);
  241.             }
  242.             else if(this._enemies[_loc1_].speedY > 0 && this._enemies[_loc1_].y >= this._enemies[_loc1_].attackParams.endPoint.y || this._enemies[_loc1_].speedY < 0 && this._enemies[_loc1_].y <= this._enemies[_loc1_].attackParams.endPoint.y)
  243.             {
  244.                this.enemyRemove(this._enemies[_loc1_]);
  245.             }
  246.             _loc1_++;
  247.          }
  248.       }
  249.       
  250.       public function enemyRemove(param1:Enemy) : void
  251.       {
  252.          param1.destroy();
  253.          var _loc2_:int = this._enemies.indexOf(param1);
  254.          if(_loc2_ != -1)
  255.          {
  256.             this._enemies.splice(_loc2_,1);
  257.          }
  258.       }
  259.       
  260.       public function enemiesRemove() : void
  261.       {
  262.          var _loc1_:int = 0;
  263.          while(_loc1_ < this._enemies.length)
  264.          {
  265.             this._enemies[_loc1_].destroy();
  266.             _loc1_++;
  267.          }
  268.          this._enemies = new Vector.<Enemy>();
  269.       }
  270.    }
  271. }
  272.