home *** CD-ROM | disk | FTP | other *** search
- class PlanetAI extends Position
- {
- var orbit_clips;
- var fire_count;
- var color;
- var target_clip;
- var onEnterFrame;
- var miss;
- var laser_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 keep_distance = 1000;
- var follow_ratio = 600;
- var fire_left = true;
- var laser_frame = 0;
- var laser_out = false;
- var health = 100;
- var redded_out = false;
- var laser_health = 100;
- var laser_redded_out = false;
- var red = {ra:100,rb:255,ga:100,gb:0,ba:100,bb:0,aa:100,ab:255};
- var normal = {ra:100,rb:0,ga:100,gb:0,ba:100,bb:0,aa:100,ab:0};
- function PlanetAI()
- {
- super();
- this.orbit_clips = [1,2,3,2,4,3,1,2];
- this.fire_count = 0;
- this.color = new Color(this);
- this.target_clip = this._parent.player;
- this.onEnterFrame = function()
- {
- if(!_global.game_paused)
- {
- this.play();
- var _loc3_ = 0;
- while(_loc3_ < 8)
- {
- this["orbit" + (_loc3_ + 1)].laser.play();
- _loc3_ = _loc3_ + 1;
- }
- if(this.redded_out)
- {
- this.unRed();
- this.redded_out = null;
- }
- else if(this.redded_out == null)
- {
- this.redded_out = false;
- }
- if(this.laser_redded_out)
- {
- this.lUnRed();
- this.laser_redded_out = null;
- }
- else if(this.laser_redded_out == null)
- {
- this.laser_redded_out = false;
- }
- if(this.fire_count++ > 3 && this.render_z < 650)
- {
- this.fire_count = 0;
- this.fireRocks();
- }
- this.followTarget();
- this.moveX();
- this.moveY();
- this.moveZ();
- }
- else
- {
- this.stop();
- _loc3_ = 0;
- while(_loc3_ < 8)
- {
- this["orbit" + (_loc3_ + 1)].laser.stop();
- _loc3_ = _loc3_ + 1;
- }
- }
- };
- }
- function followTarget()
- {
- var _loc2_ = this.distance2D(this.target_clip);
- var _loc3_ = this.posZ - (this.target_clip.posZ + this.keep_distance);
- 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.follow_ratio);
- this.accelerateY(_loc5_ * _loc2_ / this.follow_ratio);
- this.accelerateZ((- _loc3_) / 70);
- }
- function fireRocks()
- {
- this._parent.objects[this._parent.objects.length] = this._parent.attachMovie("rock","rock" + this._parent.objects.length,this._parent.getNextHighestDepth()).launch(this);
- }
- function getShot(p_hittest)
- {
- if(this.laser_frame > 54 && this.laser_out)
- {
- var _loc3_ = false;
- var _loc2_ = 0;
- while(_loc2_ < 8)
- {
- if(this["orbit" + (_loc2_ + 1)].laser.laser_target.hitTest(p_hittest))
- {
- _loc3_ = true;
- }
- _loc2_ = _loc2_ + 1;
- }
- if(_loc3_)
- {
- this.lRedOut();
- this.laser_health -= 3;
- if(this.laser_health <= 0)
- {
- this.getHurt();
- }
- }
- else if(this.miss._currentframe == 1)
- {
- this.miss.play();
- }
- }
- else if(this.miss._currentframe == 1)
- {
- this.miss.play();
- }
- }
- function getHurt()
- {
- this.redOut();
- this.health -= 20;
- var _loc2_ = 0;
- while(_loc2_ < 8)
- {
- this["orbit" + (_loc2_ + 1)].laser.gotoAndPlay(130);
- _loc2_ = _loc2_ + 1;
- }
- if(this.health <= 0)
- {
- this.die();
- }
- }
- function die()
- {
- this.gotoAndPlay(27);
- }
- function redOut()
- {
- if(this.redded_out == false)
- {
- this.color.setTransform(this.red);
- this.redded_out = true;
- }
- }
- function unRed()
- {
- this.color.setTransform(this.normal);
- this.redded_out = false;
- }
- function lRedOut()
- {
- if(this.laser_redded_out == false)
- {
- this.laser_color.setTransform(this.red);
- this.laser_redded_out = true;
- }
- }
- function lUnRed()
- {
- this.laser_color.setTransform(this.normal);
- this.laser_redded_out = false;
- }
- function updateOrbits()
- {
- this.lUnRed();
- var _loc2_ = 0;
- while(_loc2_ < 8)
- {
- this["orbit" + (_loc2_ + 1)].gotoAndStop(this.orbit_clips[_loc2_]);
- if(this.orbit_clips[_loc2_] == 5)
- {
- this.laser_color = new Color(this["orbit" + (_loc2_ + 1)].laser);
- }
- _loc2_ = _loc2_ + 1;
- }
- }
- function nextOrbit()
- {
- if(this.orbit_clips[7] == 5)
- {
- this.laser_out = false;
- }
- var _loc2_ = 7;
- while(_loc2_ >= 0)
- {
- var _loc3_ = _loc2_ + 1;
- this.orbit_clips[_loc3_] = this.orbit_clips[_loc2_];
- _loc2_ = _loc2_ - 1;
- }
- this.orbit_clips[0] = Math.ceil(Math.random() * 4);
- if(Math.random() < 0.3 && !this.laser_out)
- {
- this.laser_out = true;
- this.laser_frame = 0;
- this.laser_health = 100;
- this.orbit_clips[0] = 5;
- }
- this.updateOrbits();
- }
- 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;
- }
- }
-