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

  1. class Rock extends Position
  2. {
  3.    var speed_x;
  4.    var speed_y;
  5.    var target_clip;
  6.    var onEnterFrame;
  7.    var speed_z = -5;
  8.    var air_resistance_factor = 0.05;
  9.    var range = 80;
  10.    var health = 100;
  11.    function Rock()
  12.    {
  13.       super();
  14.       this.gotoAndStop(Math.ceil(Math.random() * 6));
  15.       this.speed_x = 4 + Math.random() * 15;
  16.       this.speed_y = -8 + Math.random() * 15;
  17.    }
  18.    function launch(p_launcher)
  19.    {
  20.       this.posX = p_launcher.posX - 400;
  21.       this.posY = p_launcher.posY + Math.random() * 50 - 25;
  22.       this.posZ = p_launcher.posZ;
  23.       var _loc4_ = p_launcher._y - 230;
  24.       this.speed_y -= _loc4_ / 5;
  25.       var _loc5_ = p_launcher._x - 275;
  26.       this.speed_x -= _loc5_ / 5;
  27.       this.target_clip = this._parent.player;
  28.       this.onEnterFrame = function()
  29.       {
  30.          if(!_global.game_paused)
  31.          {
  32.             this._rotation += 5;
  33.             this.moveX();
  34.             this.moveY();
  35.             this.moveZ();
  36.             if(this.checkTarget())
  37.             {
  38.                this.target_clip.getRocked();
  39.             }
  40.             if(this.render_z < -150 || this._y < -50 || this._y > 450 || this._x < -50 || this._x > 600)
  41.             {
  42.                this.removeMovieClip();
  43.             }
  44.          }
  45.       };
  46.       this.drawToScreen();
  47.       return this;
  48.    }
  49.    function checkTarget()
  50.    {
  51.       return this.distance3D(this.target_clip) < this.range;
  52.    }
  53.    function drawToScreen(p_player)
  54.    {
  55.       this.screenPosition(p_player);
  56.       if(this.render_z >= -300 && this.render_x > -50 - this._width && this.render_x < 600 + this._width && this.render_y > -50 - this._height && this.render_y < 450 + this._height)
  57.       {
  58.          if(this.render_z > Position.draw_distance)
  59.          {
  60.             this.offScreen();
  61.          }
  62.          else
  63.          {
  64.             if(this.render_z > Position.draw_distance - 200)
  65.             {
  66.                this._alpha = 100 - (this.render_z - Position.draw_distance + 200) / 2;
  67.             }
  68.             this.render();
  69.          }
  70.       }
  71.       else
  72.       {
  73.          this.offScreen();
  74.       }
  75.    }
  76.    function moveX()
  77.    {
  78.       this.pos_x += this.speed_x;
  79.    }
  80.    function moveY()
  81.    {
  82.       this.pos_y += this.speed_y;
  83.    }
  84.    function moveZ()
  85.    {
  86.       this.pos_z += this.speed_z;
  87.    }
  88.    function accelerateX(p_a)
  89.    {
  90.       this.speed_x += p_a;
  91.       this.speed_x -= this.speed_x * this.air_resistance_factor;
  92.    }
  93.    function accelerateY(p_a)
  94.    {
  95.       this.speed_y += p_a;
  96.       this.speed_y -= this.speed_y * this.air_resistance_factor;
  97.    }
  98.    function accelerateZ(p_a)
  99.    {
  100.       this.speed_z += p_a;
  101.    }
  102. }
  103.