home *** CD-ROM | disk | FTP | other *** search
- class EnemyAI extends TargetPosition
- {
- var fire_count;
- var extra_z;
- var extra_x;
- var extra_y;
- var target_clip;
- var onEnterFrame;
- var blast_left;
- var blast_right;
- var color;
- var speed_x = 0;
- var speed_y = 0;
- var speed_z = 0;
- var air_resistance_factor = 0.4;
- var air_resistance_factor_xy = 0.05;
- var fire_left = true;
- var has_missiles = false;
- static var missiles_out = 0;
- var health = 100;
- function EnemyAI()
- {
- super();
- this.fire_count = Math.random() * 5;
- this.extra_z = Math.random() * 200;
- this.extra_x = Math.random() * 600 - 300;
- this.extra_y = Math.random() * 600 - 300;
- this.target_clip = this._parent.player;
- this.onEnterFrame = function()
- {
- if(!_global.game_paused && this._parent == _root.airspace)
- {
- if(this._x > 0 && this._x < 550)
- {
- if(this.whited_out)
- {
- this.unWhite();
- this.whited_out = null;
- }
- else if(this.whited_out == null)
- {
- this.whited_out = false;
- }
- this.fireCannon();
- if(Math.random() < 0.015 && this.has_missiles)
- {
- this.fireMissile();
- }
- this.followTarget();
- this.keepApart();
- this.moveX();
- this.moveY();
- this.moveZ();
- }
- }
- };
- }
- function fireCannon()
- {
- if(this.fire_count++ > 5)
- {
- this.fire_count = 0;
- if(this.fire_left)
- {
- this.blast_left._visible = true;
- this.blast_left.gotoAndPlay(2);
- }
- else
- {
- this.blast_right._visible = true;
- this.blast_right.gotoAndPlay(2);
- }
- this.fire_left = !this.fire_left;
- this.shootCannon();
- }
- else
- {
- this.blast_left.gotoAndStop(1);
- this.blast_right.gotoAndStop(1);
- }
- }
- function shootCannon()
- {
- var _loc5_ = this.distance2D(this.target_clip);
- var _loc2_ = this.posZ - this.target_clip.posZ;
- var _loc3_ = 60 / _loc5_ * (600 / _loc2_);
- var _loc4_ = Math.random() * _loc3_;
- if(_loc4_ > 0.3)
- {
- this.target_clip.getShot();
- }
- }
- function fireMissile()
- {
- if(EnemyAI.missiles_out < 4)
- {
- EnemyAI.missiles_out = EnemyAI.missiles_out + 1;
- var _loc2_ = this._parent.attachMovie("enemy_missile","missile" + this._parent.objects.length,-1000 + this._parent.objects.length);
- _loc2_.launch(this,this.target_clip,50,this.speed_z);
- this._parent.addObject(_loc2_);
- }
- }
- function followTarget()
- {
- var _loc2_ = this.distance2D(this.target_clip);
- var _loc3_ = this.posZ - (this.target_clip.posZ + 800 + this.extra_z);
- var _loc4_ = 1 - 2 * (this.posX > this.target_clip.posX);
- var _loc5_ = 1 - 2 * (this.posY > this.target_clip.posY);
- this.accelerateX(_loc4_ * (_loc2_ + this.extra_x) / 200);
- this.accelerateY(_loc5_ * (_loc2_ + this.extra_y) / 200);
- this.accelerateZ((- _loc3_) / 70);
- }
- function keepApart()
- {
- for(var _loc7_ in this._parent.enemies)
- {
- if(this._parent.enemies[_loc7_] != this && this._parent.enemies[_loc7_]._x > 0 && this._parent.enemies[_loc7_]._x < 550)
- {
- var _loc4_ = this.distance2D(this._parent.enemies[_loc7_]);
- var _loc5_ = 1 - 2 * (this.posX < this._parent.enemies[_loc7_].posX);
- var _loc6_ = 1 - 2 * (this.posY < this._parent.enemies[_loc7_].posY);
- var _loc3_ = _loc5_ * 150 / _loc4_;
- var _loc2_ = _loc6_ * 150 / _loc4_;
- this.accelerateX(_loc3_ * _loc3_ * _loc3_);
- this.accelerateY(_loc2_ * _loc2_ * _loc2_);
- }
- }
- }
- function getMissiled()
- {
- this.whiteOut();
- this.reduceHealth(70);
- }
- function whiteOut()
- {
- if(this.whited_out == false)
- {
- this.color.setTransform(this.white);
- this.whited_out = true;
- }
- }
- function getShot()
- {
- this.whiteOut();
- this.reduceHealth(5.5);
- }
- function reduceHealth(p_ammount)
- {
- this.health -= p_ammount;
- if(this.health <= 0)
- {
- this.die();
- }
- }
- function die()
- {
- this._parent.goodComment();
- this._parent.enemies_killed = this._parent.enemies_killed + 1;
- this.unWhite();
- this.getShot = function()
- {
- };
- this.getMissiled = function()
- {
- };
- this.onEnterFrame = function()
- {
- if(!_global.game_paused)
- {
- if(this._x > 0 && this._x < 550)
- {
- this.moveX();
- this.moveY();
- this.moveZ();
- }
- }
- };
- this.gotoAndStop(2);
- }
- function moveX()
- {
- this.pos_x += this.speed_x;
- if(this.speed_x > 20)
- {
- this.speed_x = 20;
- }
- else if(this.speed_x < -20)
- {
- this.speed_x = -20;
- }
- }
- function moveY()
- {
- this.pos_y += this.speed_y;
- if(this.speed_y > 20)
- {
- this.speed_y = 20;
- }
- else if(this.speed_y < -20)
- {
- this.speed_y = -20;
- }
- }
- 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_xy;
- }
- function accelerateY(p_a)
- {
- this.speed_y += p_a;
- this.speed_y -= this.speed_y * this.air_resistance_factor_xy;
- }
- function accelerateZ(p_a)
- {
- this.speed_z += p_a;
- this.speed_z -= this.speed_z * this.air_resistance_factor;
- }
- }
-