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

  1. class Missile extends TargetPosition
  2. {
  3.    var target_clip;
  4.    var onEnterFrame;
  5.    var range = 40;
  6.    var exploded = false;
  7.    var speed_x = 0;
  8.    var speed_y = 0;
  9.    var speed_z = 0;
  10.    var speed_direction = 1;
  11.    var air_resistance_factor = 0.05;
  12.    var home_ratio = 70;
  13.    var missile = true;
  14.    function Missile()
  15.    {
  16.       super();
  17.    }
  18.    function launch(p_launcher, p_target_clip, p_range, p_speed, p_air_resistance_factor)
  19.    {
  20.       this.posX = p_launcher.posX;
  21.       this.posY = p_launcher.posY + 60;
  22.       this.posZ = p_launcher.posZ + 30;
  23.       this.target_clip = p_target_clip;
  24.       this.range = p_range;
  25.       if(p_speed != undefined)
  26.       {
  27.          this.speed_z = p_speed;
  28.       }
  29.       if(p_air_resistance_factor != undefined)
  30.       {
  31.          this.air_resistance_factor = p_air_resistance_factor;
  32.       }
  33.       if(this.target_clip == this._parent.player)
  34.       {
  35.          this.speed_direction = -1;
  36.       }
  37.       else
  38.       {
  39.          this.home_ratio = 20;
  40.       }
  41.       this.onEnterFrame = function()
  42.       {
  43.          if(!_global.game_paused)
  44.          {
  45.             if(!this.exploded)
  46.             {
  47.                this.accelerateZ(0.2 * this.speed_direction);
  48.                this.homeIn();
  49.                this.moveX();
  50.                this.moveY();
  51.                this.moveZ();
  52.                if(this.render_z < -200 || this.render_z > Position.draw_distance)
  53.                {
  54.                   EnemyAI.missiles_out--;
  55.                   this.removeMovieClip();
  56.                }
  57.                var _loc3_ = this._x - 275;
  58.                var _loc4_ = this._y - 200;
  59.                var _loc5_ = Math.ceil(Math.sqrt(_loc3_ * _loc3_ + _loc4_ * _loc4_) / 50);
  60.                this.gotoAndStop(_loc5_);
  61.                this._rotation = 180 * this.angleToCamera() / 3.141592653589793;
  62.                if(this.checkTarget())
  63.                {
  64.                   this.target_clip.getMissiled();
  65.                   this.exploded = true;
  66.                   if(this.target_clip == this._parent.player)
  67.                   {
  68.                      EnemyAI.missiles_out--;
  69.                   }
  70.                   this._rotation = 0;
  71.                   this.gotoAndStop(11);
  72.                }
  73.             }
  74.          }
  75.       };
  76.       this.drawToScreen();
  77.    }
  78.    function homeIn()
  79.    {
  80.       var _loc2_ = this.distance2D(this.target_clip);
  81.       var _loc3_ = 1 - 2 * (this.posX > this.target_clip.posX);
  82.       var _loc4_ = 1 - 2 * (this.posY > this.target_clip.posY);
  83.       this.accelerateX(_loc3_ * _loc2_ / this.home_ratio);
  84.       this.accelerateY(_loc4_ * _loc2_ / this.home_ratio);
  85.    }
  86.    function checkTarget()
  87.    {
  88.       return this.distance3D(this.target_clip) < this.range;
  89.    }
  90.    function moveX()
  91.    {
  92.       this.pos_x += this.speed_x;
  93.    }
  94.    function moveY()
  95.    {
  96.       this.pos_y += this.speed_y;
  97.    }
  98.    function moveZ()
  99.    {
  100.       this.pos_z += this.speed_z;
  101.    }
  102.    function accelerateX(p_a)
  103.    {
  104.       this.speed_x += p_a;
  105.       this.speed_x -= this.speed_x * this.air_resistance_factor;
  106.    }
  107.    function accelerateY(p_a)
  108.    {
  109.       this.speed_y += p_a;
  110.       this.speed_y -= this.speed_y * this.air_resistance_factor;
  111.    }
  112.    function accelerateZ(p_a)
  113.    {
  114.       this.speed_z += p_a;
  115.    }
  116. }
  117.