home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Nave / naval.swf / scripts / __Packages / CEnemyPlane.as < prev    next >
Encoding:
Text File  |  2006-06-13  |  4.9 KB  |  188 lines

  1. class CEnemyPlane extends MovieClip
  2. {
  3.    var pos;
  4.    var dir;
  5.    var speed;
  6.    var bigPlane;
  7.    var depthInMovie;
  8.    var state;
  9.    var lastDepth;
  10.    var xDir;
  11.    var lifeCount;
  12.    var removeFlag;
  13.    var shotCounter;
  14.    var curShotTime;
  15.    var timeCounter;
  16.    var myWidth2;
  17.    var myHeight2;
  18.    var myDepth2;
  19.    var toAway;
  20.    static var PLAYER;
  21.    static var SHOT_TIME = 4500;
  22.    static var SHOT_SMALL_TIME = 250;
  23.    static var NUM_SHOTS = 3;
  24.    function CEnemyPlane()
  25.    {
  26.       super();
  27.    }
  28.    function init(pos_, dir_, speed_, objTransform, bigPlane_, depthInMovie_)
  29.    {
  30.       this.pos = pos_;
  31.       this.dir = dir_;
  32.       this.speed = speed_;
  33.       this.bigPlane = bigPlane_;
  34.       this.depthInMovie = depthInMovie_;
  35.       this.state = 0;
  36.       this.lastDepth = objTransform.depth / 5.5;
  37.       if(this.dir.x > 0)
  38.       {
  39.          this.xDir = -1;
  40.       }
  41.       else
  42.       {
  43.          this.xDir = 1;
  44.       }
  45.       if(this.bigPlane)
  46.       {
  47.          this.lifeCount = 2;
  48.       }
  49.       else
  50.       {
  51.          this.lifeCount = 1;
  52.       }
  53.       this.removeFlag = false;
  54.       this.shotCounter = 0;
  55.       this.curShotTime = CEnemyPlane.SHOT_TIME * 0.3 + 3 * CEnemyPlane.SHOT_TIME * Math.random();
  56.       this.timeCounter = 0;
  57.       this.myWidth2 = this._width * 0.5;
  58.       this.myHeight2 = this._height * 0.4;
  59.       this.myDepth2 = CShot.LENGTH * 0.5;
  60.       this.toAway = false;
  61.    }
  62.    function process(dTime)
  63.    {
  64.       if(this.state == 0)
  65.       {
  66.          this.timeCounter += dTime;
  67.       }
  68.       if(this.state == 0 && this.pos.z <= this.lastDepth)
  69.       {
  70.          if(!this.bigPlane)
  71.          {
  72.             if(CEnemyPlane.PLAYER._x > this._x && this.dir.x > 0)
  73.             {
  74.                this.dir.x = - Math.abs(this.dir.x);
  75.             }
  76.             if(CEnemyPlane.PLAYER._x < this._x && this.dir.x < 0)
  77.             {
  78.                this.dir.x = Math.abs(this.dir.x);
  79.             }
  80.             if(CEnemyPlane.PLAYER._y > this._y && this.dir.y > 0)
  81.             {
  82.                this.dir.y = - Math.abs(this.dir.y);
  83.             }
  84.             if(CEnemyPlane.PLAYER._y < this._y && this.dir.y < 0)
  85.             {
  86.                this.dir.y = Math.abs(this.dir.y);
  87.             }
  88.             if(this.dir.x > 0)
  89.             {
  90.                this.xDir = -1;
  91.             }
  92.             else
  93.             {
  94.                this.xDir = 1;
  95.             }
  96.          }
  97.          if(this.dir.y > 0 && !this.bigPlane)
  98.          {
  99.             this.gotoAndStop("st_d1");
  100.          }
  101.          else
  102.          {
  103.             this.gotoAndStop("st_u1");
  104.          }
  105.          if(this.bigPlane)
  106.          {
  107.             this.dir.y = - Math.abs(this.dir.y);
  108.          }
  109.          this.state = 1;
  110.          this.toAway = true;
  111.       }
  112.       else if(this.state == 1 && this.pos.z <= this.lastDepth / 2)
  113.       {
  114.          if(!this.bigPlane)
  115.          {
  116.             if(this.dir.y > 0)
  117.             {
  118.                this.gotoAndStop("st_d2");
  119.             }
  120.             else
  121.             {
  122.                this.gotoAndStop("st_u2");
  123.             }
  124.          }
  125.          this.state = 2;
  126.       }
  127.       var _loc2_ = this.speed * dTime / 1000;
  128.       if(this.state == 0)
  129.       {
  130.          this.pos.x += this.dir.x * _loc2_;
  131.          this.pos.y += this.dir.y * _loc2_;
  132.          this.pos.z += this.dir.z * _loc2_;
  133.       }
  134.       else
  135.       {
  136.          if(this.bigPlane)
  137.          {
  138.             this.pos.x += this.dir.x * _loc2_;
  139.          }
  140.          else
  141.          {
  142.             this.pos.x += this.dir.x * _loc2_ * 140 * (this.lastDepth - this.pos.z) / this.lastDepth;
  143.          }
  144.          this.pos.y += this.dir.y * _loc2_ * 180 * (this.lastDepth - this.pos.z) / this.lastDepth;
  145.          this.pos.z += this.dir.z * _loc2_ * ((this.lastDepth - this.pos.z) / this.lastDepth + 1);
  146.       }
  147.    }
  148.    function screenSynchronize(objTransform)
  149.    {
  150.       var _loc2_ = {x:0,y:0,k:0};
  151.       objTransform.getScreenXY(this.pos.x,this.pos.y,this.pos.z,_loc2_);
  152.       this._x = _loc2_.x;
  153.       this._y = _loc2_.y;
  154.       this._xscale = (this._yscale = _loc2_.k * 100) * this.xDir;
  155.       if(this.pos.z < 0)
  156.       {
  157.          this.removeFlag = true;
  158.       }
  159.    }
  160.    function canShot()
  161.    {
  162.       return this.timeCounter >= this.curShotTime;
  163.    }
  164.    function doShot()
  165.    {
  166.       this.timeCounter = 0;
  167.       this.shotCounter = this.shotCounter + 1;
  168.       if(!this.bigPlane && this.shotCounter < CEnemyPlane.NUM_SHOTS || this.bigPlane && this.shotCounter < CEnemyPlane.NUM_SHOTS * 1.2)
  169.       {
  170.          this.curShotTime = CEnemyPlane.SHOT_SMALL_TIME;
  171.       }
  172.       else
  173.       {
  174.          this.curShotTime = CEnemyPlane.SHOT_TIME - CEnemyPlane.SHOT_TIME * 0.3 + CEnemyPlane.SHOT_TIME * 0.6 * Math.random();
  175.          this.shotCounter = 0;
  176.       }
  177.    }
  178.    function doDmage()
  179.    {
  180.       this.lifeCount = this.lifeCount - 1;
  181.       return this.lifeCount <= 0;
  182.    }
  183.    function disable()
  184.    {
  185.       this.removeMovieClip();
  186.    }
  187. }
  188.