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

  1. class WhaleAI extends Position
  2. {
  3.    var color;
  4.    var target_clip;
  5.    var onEnterFrame;
  6.    var tonsil_color;
  7.    var attack_clip;
  8.    var miss;
  9.    var speed_x = 0;
  10.    var speed_y = 0;
  11.    var speed_z = 0;
  12.    var air_resistance_factor = 0.4;
  13.    var air_resistance_factor_xy = 0.05;
  14.    var stop_list = null;
  15.    var tonsil_health = 100;
  16.    var keep_distance = 700;
  17.    var follow_ratio = 600;
  18.    var fire_left = true;
  19.    var has_missiles = false;
  20.    var health = 100;
  21.    var redded_out = false;
  22.    var tonsil_redded = false;
  23.    var red = {ra:100,rb:255,ga:100,gb:0,ba:100,bb:0,aa:100,ab:255};
  24.    var normal = {ra:100,rb:0,ga:100,gb:0,ba:100,bb:0,aa:100,ab:0};
  25.    function WhaleAI()
  26.    {
  27.       super();
  28.       this._parent.attachMovie("blank_position","tonsil_target",this._parent.getNextHighestDepth());
  29.       this._parent.objects.push(this._parent.tonsil_target);
  30.       this._parent.tonsil_target.getMissiled = function()
  31.       {
  32.          this._parent.enemy0.tonsil_health -= 30;
  33.          if(this._parent.enemy0.tonsil_health <= 0)
  34.          {
  35.             this._parent.enemy0.killTonsil();
  36.          }
  37.       };
  38.       this.color = new Color(this);
  39.       this.target_clip = this._parent.player;
  40.       this.onEnterFrame = function()
  41.       {
  42.          if(!_global.game_paused)
  43.          {
  44.             if(this.stop_list != null)
  45.             {
  46.                this.startMoving();
  47.                this.stop();
  48.             }
  49.             if(this.redded_out)
  50.             {
  51.                this.redded_out = null;
  52.             }
  53.             else if(this.redded_out == null)
  54.             {
  55.                this.unRed();
  56.             }
  57.             if(this.tonsil_redded)
  58.             {
  59.                this.tUnRed();
  60.                this.tonsil_redded = null;
  61.             }
  62.             else if(this.tonsil_redded == null)
  63.             {
  64.                this.tonsil_redded = false;
  65.             }
  66.             this.followTarget();
  67.             if(Math.random() < 0.1 && this._currentframe == 1 && this.render_z > 220 && this.render_z < 400)
  68.             {
  69.                this.tonsil_health = 100;
  70.                this.attack();
  71.                this.tonsil_color = new Color(this.attack_clip.tonsil);
  72.             }
  73.             this.moveX();
  74.             this.moveY();
  75.             this.moveZ();
  76.             this._parent.tonsil_target.posX = this.posX;
  77.             this._parent.tonsil_target.posY = this.posY + 20;
  78.             this._parent.tonsil_target.posZ = this.posZ;
  79.          }
  80.          else if(this.stop_list == null)
  81.          {
  82.             this.stopMoving();
  83.          }
  84.       };
  85.    }
  86.    function stopMoving()
  87.    {
  88.       this.stop_list = [];
  89.       for(var _loc5_ in this)
  90.       {
  91.          this.stop_list.push(this[_loc5_]);
  92.          this[_loc5_].stop();
  93.          for(var _loc4_ in this[_loc5_])
  94.          {
  95.             this.stop_list.push(this[_loc5_][_loc4_]);
  96.             this[_loc5_][_loc4_].stop();
  97.             for(var _loc3_ in this[_loc5_][_loc4_])
  98.             {
  99.                this.stop_list.push(this[_loc5_][_loc4_][_loc3_]);
  100.                this[_loc5_][_loc4_][_loc3_].stop();
  101.                for(var _loc2_ in this[_loc5_][_loc4_][_loc3_])
  102.                {
  103.                   this.stop_list.push(this[_loc5_][_loc4_][_loc3_][_loc2_]);
  104.                   this[_loc5_][_loc4_][_loc3_][_loc2_].stop();
  105.                }
  106.             }
  107.          }
  108.       }
  109.    }
  110.    function startMoving()
  111.    {
  112.       for(var _loc2_ in this.stop_list)
  113.       {
  114.          this.stop_list[_loc2_].play();
  115.       }
  116.       this.stop_list = null;
  117.    }
  118.    function followTarget()
  119.    {
  120.       var _loc2_ = this.distance2D(this.target_clip);
  121.       var _loc3_ = this.posZ - (this.target_clip.posZ + this.keep_distance);
  122.       var _loc4_ = 1 - 2 * (this.posX > this.target_clip.posX);
  123.       var _loc5_ = 1 - 2 * (this.posY > this.target_clip.posY);
  124.       this.accelerateX(_loc4_ * _loc2_ / this.follow_ratio);
  125.       this.accelerateY(_loc5_ * _loc2_ / this.follow_ratio);
  126.       this.accelerateZ((- _loc3_) / 70);
  127.    }
  128.    function attack()
  129.    {
  130.       var _loc2_ = Math.random();
  131.       if(_loc2_ > 0.07)
  132.       {
  133.          this.gotoAndStop(2);
  134.       }
  135.       else
  136.       {
  137.          this.gotoAndStop(3);
  138.          this.follow_ratio = 200;
  139.       }
  140.    }
  141.    function fireBarrels()
  142.    {
  143.       this._parent.objects[this._parent.objects.length] = this._parent.attachMovie("barrel","barrel" + this._parent.objects.length,this._parent.getNextHighestDepth()).launch(this,120);
  144.       this._parent.objects[this._parent.objects.length] = this._parent.attachMovie("barrel","barrel" + this._parent.objects.length,this._parent.getNextHighestDepth()).launch(this,-120);
  145.    }
  146.    function getShot(p_hittest)
  147.    {
  148.       if(this.attack_clip.tonsil.hitTest(p_hittest))
  149.       {
  150.          this.tRedOut();
  151.          this.tonsil_health -= 10;
  152.          if(this.tonsil_health <= 0)
  153.          {
  154.             this.killTonsil();
  155.          }
  156.       }
  157.       else if(this.miss._currentframe == 1)
  158.       {
  159.          this.miss.play();
  160.       }
  161.    }
  162.    function killTonsil()
  163.    {
  164.       this.gotoAndStop(4);
  165.       this.keep_distance = 700;
  166.       this.follow_ratio = 600;
  167.       this.getHurt();
  168.    }
  169.    function getHurt()
  170.    {
  171.       this.redOut();
  172.       this.health -= 20;
  173.       if(this.health <= 0)
  174.       {
  175.          this.die();
  176.       }
  177.    }
  178.    function die()
  179.    {
  180.       this.gotoAndStop(5);
  181.    }
  182.    function redOut()
  183.    {
  184.       if(this.redded_out == false)
  185.       {
  186.          this.color.setTransform(this.red);
  187.          this.redded_out = true;
  188.       }
  189.    }
  190.    function unRed()
  191.    {
  192.       this.color.setTransform(this.normal);
  193.       this.redded_out = false;
  194.    }
  195.    function tRedOut()
  196.    {
  197.       if(this.tonsil_redded == false)
  198.       {
  199.          this.tonsil_color.setTransform(this.red);
  200.          this.tonsil_redded = true;
  201.       }
  202.    }
  203.    function tUnRed()
  204.    {
  205.       this.tonsil_color.setTransform(this.normal);
  206.       this.tonsil_redded = false;
  207.    }
  208.    function moveX()
  209.    {
  210.       this.pos_x += this.speed_x;
  211.       if(this.speed_x > 20)
  212.       {
  213.          this.speed_x = 20;
  214.       }
  215.       else if(this.speed_x < -20)
  216.       {
  217.          this.speed_x = -20;
  218.       }
  219.    }
  220.    function moveY()
  221.    {
  222.       this.pos_y += this.speed_y;
  223.       if(this.speed_y > 20)
  224.       {
  225.          this.speed_y = 20;
  226.       }
  227.       else if(this.speed_y < -20)
  228.       {
  229.          this.speed_y = -20;
  230.       }
  231.    }
  232.    function moveZ()
  233.    {
  234.       this.pos_z += this.speed_z;
  235.    }
  236.    function accelerateX(p_a)
  237.    {
  238.       this.speed_x += p_a;
  239.       this.speed_x -= this.speed_x * this.air_resistance_factor_xy;
  240.    }
  241.    function accelerateY(p_a)
  242.    {
  243.       this.speed_y += p_a;
  244.       this.speed_y -= this.speed_y * this.air_resistance_factor_xy;
  245.    }
  246.    function accelerateZ(p_a)
  247.    {
  248.       this.speed_z += p_a;
  249.       this.speed_z -= this.speed_z * this.air_resistance_factor;
  250.    }
  251. }
  252.