home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Nave / rocket_rush.swf / scripts / __Packages / BlimpAI.as < prev    next >
Encoding:
Text File  |  2007-03-20  |  5.7 KB  |  214 lines

  1. class BlimpAI extends Position
  2. {
  3.    var color;
  4.    var target_clip;
  5.    var onEnterFrame;
  6.    var attack_clip;
  7.    var miss;
  8.    var speed_x = 0;
  9.    var speed_y = 0;
  10.    var speed_z = 0;
  11.    var air_resistance_factor = 0.4;
  12.    var air_resistance_factor_xy = 0.05;
  13.    var stop_list = null;
  14.    var targs_hit = [false,false,false,false];
  15.    var fire_left = true;
  16.    var has_missiles = false;
  17.    var health = 100;
  18.    var redded_out = false;
  19.    var red = {ra:100,rb:255,ga:100,gb:0,ba:100,bb:0,aa:100,ab:255};
  20.    var normal = {ra:100,rb:0,ga:100,gb:0,ba:100,bb:0,aa:100,ab:0};
  21.    function BlimpAI()
  22.    {
  23.       super();
  24.       this.color = new Color(this);
  25.       this.target_clip = this._parent.player;
  26.       this.onEnterFrame = function()
  27.       {
  28.          if(!_global.game_paused)
  29.          {
  30.             if(this.stop_list != null)
  31.             {
  32.                this.startMoving();
  33.                this.stop();
  34.             }
  35.             if(this.redded_out)
  36.             {
  37.                this.redded_out = null;
  38.             }
  39.             else if(this.redded_out == null)
  40.             {
  41.                this.unRed();
  42.             }
  43.             this.followTarget();
  44.             if(Math.random() < 0.01 && this._currentframe == 1 && this.render_z < 500)
  45.             {
  46.                this.targs_hit = [false,false,false,false];
  47.                this.attack();
  48.             }
  49.             this.moveX();
  50.             this.moveY();
  51.             this.moveZ();
  52.          }
  53.          else if(this.stop_list == null)
  54.          {
  55.             this.stopMoving();
  56.          }
  57.       };
  58.    }
  59.    function stopMoving()
  60.    {
  61.       this.stop_list = [];
  62.       for(var _loc5_ in this)
  63.       {
  64.          this.stop_list.push(this[_loc5_]);
  65.          this[_loc5_].stop();
  66.          for(var _loc4_ in this[_loc5_])
  67.          {
  68.             this.stop_list.push(this[_loc5_][_loc4_]);
  69.             this[_loc5_][_loc4_].stop();
  70.             for(var _loc3_ in this[_loc5_][_loc4_])
  71.             {
  72.                this.stop_list.push(this[_loc5_][_loc4_][_loc3_]);
  73.                this[_loc5_][_loc4_][_loc3_].stop();
  74.                for(var _loc2_ in this[_loc5_][_loc4_][_loc3_])
  75.                {
  76.                   this.stop_list.push(this[_loc5_][_loc4_][_loc3_][_loc2_]);
  77.                   this[_loc5_][_loc4_][_loc3_][_loc2_].stop();
  78.                }
  79.             }
  80.          }
  81.       }
  82.    }
  83.    function startMoving()
  84.    {
  85.       for(var _loc2_ in this.stop_list)
  86.       {
  87.          this.stop_list[_loc2_].play();
  88.       }
  89.       this.stop_list = null;
  90.    }
  91.    function followTarget()
  92.    {
  93.       var _loc2_ = this.distance2D(this.target_clip);
  94.       var _loc3_ = this.posZ - (this.target_clip.posZ + 700);
  95.       var _loc4_ = 1 - 2 * (this.posX > this.target_clip.posX);
  96.       var _loc5_ = 1 - 2 * (this.posY > this.target_clip.posY);
  97.       this.accelerateX(_loc4_ * _loc2_ / 600);
  98.       this.accelerateY(_loc5_ * _loc2_ / 600);
  99.       this.accelerateZ((- _loc3_) / 70);
  100.    }
  101.    function attack()
  102.    {
  103.       var _loc2_ = Math.ceil(Math.random() * 3) + 1;
  104.       this.gotoAndStop(_loc2_);
  105.    }
  106.    function fireEnergyBall()
  107.    {
  108.       this._parent.objects[this._parent.objects.length] = this._parent.attachMovie("energy_ball","eball" + this._parent.objects.length,this._parent.getNextHighestDepth()).launch(this,80,-10);
  109.    }
  110.    function getShot(p_hittest)
  111.    {
  112.       var _loc2_ = 1;
  113.       while(_loc2_ < 5)
  114.       {
  115.          var _loc3_ = this.attack_clip["chainout" + _loc2_];
  116.          if(_loc3_.targ.hitTest(p_hittest))
  117.          {
  118.             _loc3_.gotoAndStop(28);
  119.             this.targs_hit[_loc2_ - 1] = true;
  120.          }
  121.          else if(_loc3_.chain.targ.hitTest(p_hittest))
  122.          {
  123.             _loc3_.chain.gotoAndStop(11);
  124.             this.targs_hit[_loc2_ - 1] = true;
  125.          }
  126.          else if(this.miss._currentframe == 1)
  127.          {
  128.             this.miss.play();
  129.          }
  130.          if(this.targs_hit[0] && this.targs_hit[1] && this.targs_hit[2] && this.targs_hit[3])
  131.          {
  132.             this.attack_clip.nose.gotoAndStop(3);
  133.          }
  134.          if(this.attack_clip.nose._currentframe == 3 && this.attack_clip.nose.hitTest(p_hittest))
  135.          {
  136.             this.targs_hit = [false,false,false,false];
  137.             this.gotoAndStop(1);
  138.             this.getHurt();
  139.          }
  140.          _loc2_ = _loc2_ + 1;
  141.       }
  142.    }
  143.    function getHurt()
  144.    {
  145.       this.redOut();
  146.       this.health -= 20;
  147.       this.gotoAndStop(6);
  148.       if(this.health <= 0)
  149.       {
  150.          this.die();
  151.       }
  152.    }
  153.    function die()
  154.    {
  155.       this.gotoAndStop(5);
  156.    }
  157.    function redOut()
  158.    {
  159.       if(!this.redded_out)
  160.       {
  161.          this.color.setTransform(this.red);
  162.          this.redded_out = true;
  163.       }
  164.    }
  165.    function unRed()
  166.    {
  167.       this.color.setTransform(this.normal);
  168.       this.redded_out = false;
  169.    }
  170.    function moveX()
  171.    {
  172.       this.pos_x += this.speed_x;
  173.       if(this.speed_x > 20)
  174.       {
  175.          this.speed_x = 20;
  176.       }
  177.       else if(this.speed_x < -20)
  178.       {
  179.          this.speed_x = -20;
  180.       }
  181.    }
  182.    function moveY()
  183.    {
  184.       this.pos_y += this.speed_y;
  185.       if(this.speed_y > 20)
  186.       {
  187.          this.speed_y = 20;
  188.       }
  189.       else if(this.speed_y < -20)
  190.       {
  191.          this.speed_y = -20;
  192.       }
  193.    }
  194.    function moveZ()
  195.    {
  196.       this.pos_z += this.speed_z;
  197.    }
  198.    function accelerateX(p_a)
  199.    {
  200.       this.speed_x += p_a;
  201.       this.speed_x -= this.speed_x * this.air_resistance_factor_xy;
  202.    }
  203.    function accelerateY(p_a)
  204.    {
  205.       this.speed_y += p_a;
  206.       this.speed_y -= this.speed_y * this.air_resistance_factor_xy;
  207.    }
  208.    function accelerateZ(p_a)
  209.    {
  210.       this.speed_z += p_a;
  211.       this.speed_z -= this.speed_z * this.air_resistance_factor;
  212.    }
  213. }
  214.