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

  1. class Position extends MovieClip
  2. {
  3.    var pos_x = 0;
  4.    var pos_y = 0;
  5.    var pos_z = 0;
  6.    var render_x = 0;
  7.    var render_y = 0;
  8.    var render_z = 0;
  9.    var render_scale = 0;
  10.    var render_depth = 0;
  11.    var started = false;
  12.    var missile = false;
  13.    var boss = false;
  14.    static var camera_x = 0;
  15.    static var camera_y = 0;
  16.    static var camera_z = 0;
  17.    static var camera_depth = 300;
  18.    static var center_x = 275;
  19.    static var center_y = 200;
  20.    static var center_y_offset = 100;
  21.    static var draw_distance = 1500;
  22.    function Position()
  23.    {
  24.       super();
  25.    }
  26.    function screenPosition()
  27.    {
  28.       this.render_z = this.pos_z - Position.camera_z;
  29.       this.render_scale = Position.camera_depth / (this.render_z + Position.camera_depth);
  30.       this.render_x = Position.center_x + (this.pos_x - Position.camera_x) * this.render_scale;
  31.       this.render_y = Position.center_y + (this.pos_y - Position.camera_y + Position.center_y_offset) * this.render_scale;
  32.       this.render_depth = Math.round(this.render_scale * 1000);
  33.       if(this.pos_x == NaN || this.pos_y == NaN || this.pos_z == NaN)
  34.       {
  35.          this.removeMovieClip();
  36.       }
  37.    }
  38.    function render()
  39.    {
  40.       this._x = this.render_x;
  41.       this._y = this.render_y;
  42.       this._xscale = this._yscale = 100 * this.render_scale;
  43.       this.swapDepths(this.render_depth);
  44.       this.blur(this.render_z);
  45.    }
  46.    function blur(p_y)
  47.    {
  48.       var _loc2_ = (p_y - 200) / 500;
  49.       var _loc3_ = new flash.filters.BlurFilter(_loc2_,_loc2_,1);
  50.       this.filters = [_loc3_];
  51.    }
  52.    function offScreen()
  53.    {
  54.       this._x = -200;
  55.       this._y = -200;
  56.       this._xscale = this._yscale = 5;
  57.    }
  58.    function drawToScreen()
  59.    {
  60.       this.screenPosition();
  61.       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)
  62.       {
  63.          if(this.render_z > Position.draw_distance)
  64.          {
  65.             this.offScreen();
  66.          }
  67.          else
  68.          {
  69.             if(this.render_z > Position.draw_distance - 200)
  70.             {
  71.                this._alpha = 100 - (this.render_z - Position.draw_distance + 200) / 2;
  72.             }
  73.             else
  74.             {
  75.                this._alpha = 100;
  76.             }
  77.             this.render();
  78.          }
  79.       }
  80.       else
  81.       {
  82.          this.offScreen();
  83.       }
  84.    }
  85.    function cameraFollow(p_position)
  86.    {
  87.       var _loc1_ = undefined;
  88.       if(p_position.boss)
  89.       {
  90.          _loc1_ = true;
  91.       }
  92.       else if(p_position.posZ > 25000)
  93.       {
  94.          _loc1_ = false;
  95.       }
  96.       else
  97.       {
  98.          _loc1_ = true;
  99.       }
  100.       if(_loc1_)
  101.       {
  102.          Position.camera_x += (p_position.posX - Position.camera_x) / 5;
  103.          Position.camera_y += (p_position.posY - Position.camera_y) / 5;
  104.          Position.camera_z = p_position.posZ;
  105.       }
  106.    }
  107.    function distance2D(p_position)
  108.    {
  109.       var _loc3_ = this.posX - p_position.posX;
  110.       var _loc2_ = this.posY - p_position.posY;
  111.       return Math.sqrt(_loc3_ * _loc3_ + _loc2_ * _loc2_);
  112.    }
  113.    function distance3D(p_position)
  114.    {
  115.       var _loc4_ = this.posX - p_position.posX;
  116.       var _loc3_ = this.posY - p_position.posY;
  117.       var _loc2_ = this.posZ - p_position.posZ;
  118.       return Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_ + _loc2_ * _loc2_);
  119.    }
  120.    function angle2D(p_position)
  121.    {
  122.       var _loc3_ = p_position.posX - this.pos_x;
  123.       var _loc2_ = this.pos_y - p_position.posY;
  124.       return Math.atan2(_loc3_,_loc2_);
  125.    }
  126.    function angleToCamera()
  127.    {
  128.       var _loc3_ = Position.camera_x - this.pos_x;
  129.       var _loc2_ = this.pos_y - Position.camera_y;
  130.       return Math.atan2(_loc3_,_loc2_);
  131.    }
  132.    static function get cameraDepth()
  133.    {
  134.       return Position.camera_depth;
  135.    }
  136.    static function set cameraDepth(p_depth)
  137.    {
  138.       Position.camera_depth = p_depth;
  139.    }
  140.    function get posX()
  141.    {
  142.       return this.pos_x;
  143.    }
  144.    function set posX(p_x)
  145.    {
  146.       this.pos_x = p_x;
  147.    }
  148.    function get posY()
  149.    {
  150.       return this.pos_y;
  151.    }
  152.    function set posY(p_y)
  153.    {
  154.       this.pos_y = p_y;
  155.    }
  156.    function get posZ()
  157.    {
  158.       return this.pos_z;
  159.    }
  160.    function set posZ(p_z)
  161.    {
  162.       this.pos_z = p_z;
  163.    }
  164.    function get renderX()
  165.    {
  166.       return this.render_x;
  167.    }
  168.    function get renderY()
  169.    {
  170.       return this.render_y;
  171.    }
  172.    function get renderZ()
  173.    {
  174.       return this.render_y;
  175.    }
  176.    function get renderScale()
  177.    {
  178.       return this.render_scale;
  179.    }
  180.    function get renderDepth()
  181.    {
  182.       return this.render_depth;
  183.    }
  184.    function getShot()
  185.    {
  186.    }
  187. }
  188.