home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / climatechaos.swf / scripts / __Packages / Position.as < prev    next >
Encoding:
Text File  |  2008-09-12  |  2.6 KB  |  111 lines

  1. class Position extends MovieClip
  2. {
  3.    var depth_count;
  4.    var offscreen;
  5.    var pos_x;
  6.    var pos_y;
  7.    var radius;
  8.    var nx;
  9.    var ny;
  10.    var environment;
  11.    var z;
  12.    var zs;
  13.    function Position()
  14.    {
  15.       super();
  16.       this.depth_count = 0;
  17.       this.offscreen = false;
  18.       this.pos_x = 0;
  19.       this.pos_y = 0;
  20.       this.radius = 20;
  21.       this.nx = 0;
  22.       this.ny = 0;
  23.    }
  24.    function distanceTo(p_x, p_y)
  25.    {
  26.       var _loc3_ = this.pos_x - p_x;
  27.       var _loc2_ = this.pos_y - p_y;
  28.       return Math.sqrt(_loc3_ * _loc3_ + _loc2_ * _loc2_);
  29.    }
  30.    function angleTo(p_x, p_y)
  31.    {
  32.       var _loc3_ = p_x - this.pos_x;
  33.       var _loc4_ = this.pos_y - p_y;
  34.       var _loc2_ = Math.atan2(_loc3_,_loc4_);
  35.       return _loc2_;
  36.    }
  37.    function positive(p_n)
  38.    {
  39.       var _loc1_ = p_n;
  40.       if(_loc1_ < 0)
  41.       {
  42.          _loc1_ *= -1;
  43.       }
  44.       return _loc1_;
  45.    }
  46.    function blur(p_y)
  47.    {
  48.       var _loc2_ = 3 - (p_y - 160) / 15;
  49.       var _loc3_ = new flash.filters.BlurFilter(_loc2_,_loc2_,1);
  50.       this.filters = [_loc3_];
  51.    }
  52.    function fade()
  53.    {
  54.       if(this._y > 280)
  55.       {
  56.          this._alpha = 100 - (this.ny - 300) * 5;
  57.       }
  58.       else
  59.       {
  60.          this._alpha = 100;
  61.       }
  62.    }
  63.    function posit(p_env)
  64.    {
  65.       this.environment = p_env;
  66.       this.z = -300 - this.pos_y + p_env.pos_y;
  67.       this.zs = p_env.camera_depth / (this.z + p_env.camera_depth);
  68.       this.nx = 275 + (- p_env.pos_x + this.pos_x) * this.zs;
  69.       this.ny = 100 + p_env.camera_offset * this.zs;
  70.    }
  71.    function depth()
  72.    {
  73.       this.swapDepths(this.environment.level_list[this._name]);
  74.    }
  75.    function render(p_env)
  76.    {
  77.       this.posit(p_env);
  78.       if(this.nx < 650 && this.nx > -100 && this.z > -350)
  79.       {
  80.          this.offscreen = false;
  81.          this._x = this.nx;
  82.          this._y = this.ny;
  83.          this._xscale = this._yscale = 40 * this.zs;
  84.          this.depth();
  85.          this.blur(this.ny);
  86.          this.fade();
  87.       }
  88.       else if(this.offscreen == false)
  89.       {
  90.          this.offscreen = true;
  91.          this._x = -200;
  92.          this._y = -200;
  93.       }
  94.    }
  95.    function collide(p_new_x, p_new_y)
  96.    {
  97.       var _loc3_ = p_new_x;
  98.       var _loc2_ = p_new_y;
  99.       if(this.radius > 0)
  100.       {
  101.          if(this.distanceTo(_loc3_,_loc2_) < this.radius)
  102.          {
  103.             var _loc4_ = this.angleTo(_loc3_,_loc2_);
  104.             _loc3_ = this.pos_x + Math.sin(_loc4_) * this.radius;
  105.             _loc2_ = this.pos_y - Math.cos(_loc4_) * this.radius;
  106.          }
  107.       }
  108.       return [_loc3_,_loc2_];
  109.    }
  110. }
  111.