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

  1. class CShip extends MovieClip
  2. {
  3.    var myType;
  4.    var speed;
  5.    var pos;
  6.    var depthInMovie;
  7.    var lifeCount;
  8.    var shotCounter;
  9.    var curShotTime;
  10.    var timeCounter;
  11.    var removeFlag;
  12.    var myWidth2;
  13.    var myScale;
  14.    static var PLAYER;
  15.    static var SHOT_TIME = 8000;
  16.    static var SHOT_SMALL_TIME = 400;
  17.    static var NUM_SHOTS = 3;
  18.    static var SCREEN_WIDTH = 550;
  19.    function CShip()
  20.    {
  21.       super();
  22.    }
  23.    function init(myType_, speed_, pos_, depthInMovie_)
  24.    {
  25.       this.myType = myType_;
  26.       this.speed = speed_;
  27.       this.pos = pos_;
  28.       this.depthInMovie = depthInMovie_;
  29.       if(this.myType == 2)
  30.       {
  31.          this.lifeCount = 2;
  32.       }
  33.       else
  34.       {
  35.          this.lifeCount = 1;
  36.       }
  37.       this.shotCounter = 0;
  38.       this.curShotTime = CShip.SHOT_TIME - CShip.SHOT_TIME * 0.3 + CShip.SHOT_TIME * 0.6 * Math.random();
  39.       this.timeCounter = 0;
  40.       this.removeFlag = false;
  41.       this.myWidth2 = this._width * 0.29;
  42.       if(this.myType == 1)
  43.       {
  44.          this.myScale = 0.75;
  45.       }
  46.       else
  47.       {
  48.          this.myScale = 1.3;
  49.       }
  50.    }
  51.    function process(dTime)
  52.    {
  53.       var _loc2_ = this.speed * dTime / 1000;
  54.       this.timeCounter += dTime;
  55.       this.pos.x += _loc2_;
  56.    }
  57.    function screenSynchronize(objTransform)
  58.    {
  59.       var _loc2_ = {x:0,y:0,k:0};
  60.       objTransform.getScreenXY(this.pos.x,this.pos.y,this.pos.z,_loc2_);
  61.       this._x = _loc2_.x;
  62.       this._y = _loc2_.y;
  63.       this._xscale = this._yscale = _loc2_.k * 150;
  64.       if(this.pos.x >= objTransform.nearWidth && this._x - this._width / 2 >= CShip.SCREEN_WIDTH)
  65.       {
  66.          this.removeFlag = true;
  67.       }
  68.       var _loc6_ = objTransform.nearHeight - CShip.PLAYER.y;
  69.       var _loc5_ = Math.sqrt((this.pos.x - CShip.PLAYER.x) * (this.pos.x - CShip.PLAYER.x) + this.pos.z * this.pos.z);
  70.       var _loc3_ = _loc6_ / _loc5_;
  71.       if(_loc3_ < 0.66)
  72.       {
  73.          this.gotoAndStop(1);
  74.       }
  75.       else if(_loc3_ < 1.2)
  76.       {
  77.          this.gotoAndStop(2);
  78.       }
  79.       else
  80.       {
  81.          this.gotoAndStop(3);
  82.       }
  83.    }
  84.    function canShot()
  85.    {
  86.       return this.myType > 0 && this.timeCounter >= this.curShotTime;
  87.    }
  88.    function doShot()
  89.    {
  90.       this.timeCounter = 0;
  91.       this.shotCounter = this.shotCounter + 1;
  92.       if(this.shotCounter < CShip.NUM_SHOTS)
  93.       {
  94.          this.curShotTime = CShip.SHOT_SMALL_TIME;
  95.       }
  96.       else
  97.       {
  98.          this.curShotTime = CShip.SHOT_TIME - CShip.SHOT_TIME * 0.3 + CShip.SHOT_TIME * 0.6 * Math.random();
  99.          this.shotCounter = 0;
  100.       }
  101.    }
  102.    function doDmage()
  103.    {
  104.       this.lifeCount = this.lifeCount - 1;
  105.       return this.lifeCount <= 0;
  106.    }
  107.    function disable()
  108.    {
  109.       this.removeMovieClip();
  110.    }
  111. }
  112.