home *** CD-ROM | disk | FTP | other *** search
- class WhaleAI extends Position
- {
- var color;
- var target_clip;
- var onEnterFrame;
- var tonsil_color;
- var attack_clip;
- var miss;
- 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 stop_list = null;
- var tonsil_health = 100;
- var keep_distance = 700;
- var follow_ratio = 600;
- var fire_left = true;
- var has_missiles = false;
- var health = 100;
- var redded_out = false;
- var tonsil_redded = 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 WhaleAI()
- {
- super();
- this._parent.attachMovie("blank_position","tonsil_target",this._parent.getNextHighestDepth());
- this._parent.objects.push(this._parent.tonsil_target);
- this._parent.tonsil_target.getMissiled = function()
- {
- this._parent.enemy0.tonsil_health -= 30;
- if(this._parent.enemy0.tonsil_health <= 0)
- {
- this._parent.enemy0.killTonsil();
- }
- };
- this.color = new Color(this);
- this.target_clip = this._parent.player;
- this.onEnterFrame = function()
- {
- if(!_global.game_paused)
- {
- if(this.stop_list != null)
- {
- this.startMoving();
- this.stop();
- }
- if(this.redded_out)
- {
- this.redded_out = null;
- }
- else if(this.redded_out == null)
- {
- this.unRed();
- }
- if(this.tonsil_redded)
- {
- this.tUnRed();
- this.tonsil_redded = null;
- }
- else if(this.tonsil_redded == null)
- {
- this.tonsil_redded = false;
- }
- this.followTarget();
- if(Math.random() < 0.1 && this._currentframe == 1 && this.render_z > 220 && this.render_z < 400)
- {
- this.tonsil_health = 100;
- this.attack();
- this.tonsil_color = new Color(this.attack_clip.tonsil);
- }
- this.moveX();
- this.moveY();
- this.moveZ();
- this._parent.tonsil_target.posX = this.posX;
- this._parent.tonsil_target.posY = this.posY + 20;
- this._parent.tonsil_target.posZ = this.posZ;
- }
- else if(this.stop_list == null)
- {
- this.stopMoving();
- }
- };
- }
- function stopMoving()
- {
- this.stop_list = [];
- for(var _loc5_ in this)
- {
- this.stop_list.push(this[_loc5_]);
- this[_loc5_].stop();
- for(var _loc4_ in this[_loc5_])
- {
- this.stop_list.push(this[_loc5_][_loc4_]);
- this[_loc5_][_loc4_].stop();
- for(var _loc3_ in this[_loc5_][_loc4_])
- {
- this.stop_list.push(this[_loc5_][_loc4_][_loc3_]);
- this[_loc5_][_loc4_][_loc3_].stop();
- for(var _loc2_ in this[_loc5_][_loc4_][_loc3_])
- {
- this.stop_list.push(this[_loc5_][_loc4_][_loc3_][_loc2_]);
- this[_loc5_][_loc4_][_loc3_][_loc2_].stop();
- }
- }
- }
- }
- }
- function startMoving()
- {
- for(var _loc2_ in this.stop_list)
- {
- this.stop_list[_loc2_].play();
- }
- this.stop_list = null;
- }
- 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 attack()
- {
- var _loc2_ = Math.random();
- if(_loc2_ > 0.07)
- {
- this.gotoAndStop(2);
- }
- else
- {
- this.gotoAndStop(3);
- this.follow_ratio = 200;
- }
- }
- function fireBarrels()
- {
- this._parent.objects[this._parent.objects.length] = this._parent.attachMovie("barrel","barrel" + this._parent.objects.length,this._parent.getNextHighestDepth()).launch(this,120);
- this._parent.objects[this._parent.objects.length] = this._parent.attachMovie("barrel","barrel" + this._parent.objects.length,this._parent.getNextHighestDepth()).launch(this,-120);
- }
- function getShot(p_hittest)
- {
- if(this.attack_clip.tonsil.hitTest(p_hittest))
- {
- this.tRedOut();
- this.tonsil_health -= 10;
- if(this.tonsil_health <= 0)
- {
- this.killTonsil();
- }
- }
- else if(this.miss._currentframe == 1)
- {
- this.miss.play();
- }
- }
- function killTonsil()
- {
- this.gotoAndStop(4);
- this.keep_distance = 700;
- this.follow_ratio = 600;
- this.getHurt();
- }
- function getHurt()
- {
- this.redOut();
- this.health -= 20;
- if(this.health <= 0)
- {
- this.die();
- }
- }
- function die()
- {
- this.gotoAndStop(5);
- }
- 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 tRedOut()
- {
- if(this.tonsil_redded == false)
- {
- this.tonsil_color.setTransform(this.red);
- this.tonsil_redded = true;
- }
- }
- function tUnRed()
- {
- this.tonsil_color.setTransform(this.normal);
- this.tonsil_redded = false;
- }
- 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;
- }
- }
-