home *** CD-ROM | disk | FTP | other *** search
- class Missile extends TargetPosition
- {
- var target_clip;
- var onEnterFrame;
- var range = 40;
- var exploded = false;
- var speed_x = 0;
- var speed_y = 0;
- var speed_z = 0;
- var speed_direction = 1;
- var air_resistance_factor = 0.05;
- var home_ratio = 70;
- var missile = true;
- function Missile()
- {
- super();
- }
- function launch(p_launcher, p_target_clip, p_range, p_speed, p_air_resistance_factor)
- {
- this.posX = p_launcher.posX;
- this.posY = p_launcher.posY + 60;
- this.posZ = p_launcher.posZ + 30;
- this.target_clip = p_target_clip;
- this.range = p_range;
- if(p_speed != undefined)
- {
- this.speed_z = p_speed;
- }
- if(p_air_resistance_factor != undefined)
- {
- this.air_resistance_factor = p_air_resistance_factor;
- }
- if(this.target_clip == this._parent.player)
- {
- this.speed_direction = -1;
- }
- else
- {
- this.home_ratio = 20;
- }
- this.onEnterFrame = function()
- {
- if(!_global.game_paused)
- {
- if(!this.exploded)
- {
- this.accelerateZ(0.2 * this.speed_direction);
- this.homeIn();
- this.moveX();
- this.moveY();
- this.moveZ();
- if(this.render_z < -200 || this.render_z > Position.draw_distance)
- {
- EnemyAI.missiles_out--;
- this.removeMovieClip();
- }
- var _loc3_ = this._x - 275;
- var _loc4_ = this._y - 200;
- var _loc5_ = Math.ceil(Math.sqrt(_loc3_ * _loc3_ + _loc4_ * _loc4_) / 50);
- this.gotoAndStop(_loc5_);
- this._rotation = 180 * this.angleToCamera() / 3.141592653589793;
- if(this.checkTarget())
- {
- this.target_clip.getMissiled();
- this.exploded = true;
- if(this.target_clip == this._parent.player)
- {
- EnemyAI.missiles_out--;
- }
- this._rotation = 0;
- this.gotoAndStop(11);
- }
- }
- }
- };
- this.drawToScreen();
- }
- function homeIn()
- {
- var _loc2_ = this.distance2D(this.target_clip);
- var _loc3_ = 1 - 2 * (this.posX > this.target_clip.posX);
- var _loc4_ = 1 - 2 * (this.posY > this.target_clip.posY);
- this.accelerateX(_loc3_ * _loc2_ / this.home_ratio);
- this.accelerateY(_loc4_ * _loc2_ / this.home_ratio);
- }
- function checkTarget()
- {
- return this.distance3D(this.target_clip) < this.range;
- }
- function moveX()
- {
- this.pos_x += this.speed_x;
- }
- function moveY()
- {
- this.pos_y += this.speed_y;
- }
- function moveZ()
- {
- this.pos_z += this.speed_z;
- }
- function accelerateX(p_a)
- {
- this.speed_x += p_a;
- this.speed_x -= this.speed_x * this.air_resistance_factor;
- }
- function accelerateY(p_a)
- {
- this.speed_y += p_a;
- this.speed_y -= this.speed_y * this.air_resistance_factor;
- }
- function accelerateZ(p_a)
- {
- this.speed_z += p_a;
- }
- }
-