home *** CD-ROM | disk | FTP | other *** search
/ One Click 21 (Special) / OC021.iso / Juegos / 05-11-10-1.swf / scripts / __Packages / Utils.as < prev    next >
Encoding:
Text File  |  2005-11-18  |  3.8 KB  |  137 lines

  1. class Utils
  2. {
  3.    var MAP_WIDTH_CELL = 40;
  4.    var WIDTH_CELL = 70;
  5.    var WIDTH_SCREEN = 400;
  6.    var MAP_SCALE_FACTOR = 24;
  7.    var PARALLAX_SCALE_FACTOR = 16;
  8.    var posCenterScreen = new Object();
  9.    function Utils()
  10.    {
  11.       this.posCenterScreen.x = 400;
  12.       this.posCenterScreen.y = 400;
  13.    }
  14.    function ConvertHitPosToMap(l_coord)
  15.    {
  16.       l_coord.x = - l_coord.x * this.MAP_SCALE_FACTOR + this.posCenterScreen.x;
  17.       l_coord.y = - l_coord.y * this.MAP_SCALE_FACTOR + this.posCenterScreen.y;
  18.       return l_coord;
  19.    }
  20.    function ConvertHitPosToParallax1(l_coord)
  21.    {
  22.       l_coord.x = - l_coord.x * this.PARALLAX_SCALE_FACTOR + this.posCenterScreen.x + 25;
  23.       l_coord.y = - l_coord.y * this.PARALLAX_SCALE_FACTOR;
  24.       return l_coord;
  25.    }
  26.    function ConvertHitPosToParallax2(l_coord)
  27.    {
  28.       l_coord.x = - l_coord.x * this.PARALLAX_SCALE_FACTOR + this.posCenterScreen.x;
  29.       l_coord.y = - l_coord.y * this.PARALLAX_SCALE_FACTOR + this.posCenterScreen.y;
  30.       return l_coord;
  31.    }
  32.    function ConvertHitPosToParallax3(l_coord)
  33.    {
  34.       l_coord.x = - l_coord.x * this.PARALLAX_SCALE_FACTOR + this.posCenterScreen.x;
  35.       l_coord.y = - l_coord.y * this.PARALLAX_SCALE_FACTOR + this.posCenterScreen.y;
  36.       return l_coord;
  37.    }
  38.    function GetAbsDistBetweenObj(l_objA, l_objB)
  39.    {
  40.       var _loc1_ = l_objA.GetStageCoord();
  41.       var _loc2_ = l_objB.GetStageCoord();
  42.       return Math.sqrt((_loc1_.x - _loc2_.x) * (_loc1_.x - _loc2_.x) + (_loc1_.y - _loc2_.y) * (_loc1_.y - _loc2_.y));
  43.    }
  44.    function GetHitZone(l_coord)
  45.    {
  46.       var _loc3_ = l_coord;
  47.       _global.C._parent.ScrollMap.Items.Map.HitContainer.globalToLocal(_loc3_);
  48.       _loc3_.x = Math.ceil(_loc3_.x / this.WIDTH_CELL);
  49.       _loc3_.y = Math.ceil(_loc3_.y / this.WIDTH_CELL);
  50.       return _loc3_;
  51.    }
  52.    function GetMapZone(l_coord)
  53.    {
  54.       var _loc3_ = l_coord;
  55.       _global.C._parent.ScrollMap.Items.Map.HitContainer.globalToLocal(_loc3_);
  56.       _loc3_.x = Math.ceil(_loc3_.x / (this.MAP_WIDTH_CELL / 8));
  57.       _loc3_.y = Math.ceil(_loc3_.y / (this.MAP_WIDTH_CELL / 8));
  58.       return _loc3_;
  59.    }
  60.    function GetDiffZone(l_mainZone, l_secondZone)
  61.    {
  62.       var _loc1_ = new Object();
  63.       _loc1_.x = l_mainZone.x - l_secondZone.x;
  64.       _loc1_.y = l_mainZone.y - l_secondZone.y;
  65.       return _loc1_;
  66.    }
  67.    function GetDirBetweenObject(l_mainObj, l_destObj)
  68.    {
  69.       var _loc5_ = l_mainObj.GetZone();
  70.       var _loc6_ = l_destObj.GetZone();
  71.       var _loc7_ = this.WIDTH_SCREEN / this.MAP_WIDTH_CELL;
  72.       var _loc4_ = _loc5_.x - _loc6_.x;
  73.       var _loc3_ = _loc5_.y - _loc6_.y;
  74.       var _loc2_ = null;
  75.       if(_loc4_ == 0 && _loc3_ == 0)
  76.       {
  77.          _loc2_ = "same";
  78.       }
  79.       else if(_loc4_ == 0)
  80.       {
  81.          if(_loc3_ > 0)
  82.          {
  83.             _loc2_ = "n";
  84.          }
  85.          else
  86.          {
  87.             _loc2_ = "s";
  88.          }
  89.       }
  90.       else if(_loc3_ == 0)
  91.       {
  92.          if(_loc4_ > 0)
  93.          {
  94.             _loc2_ = "w";
  95.          }
  96.          else
  97.          {
  98.             _loc2_ = "e";
  99.          }
  100.       }
  101.       else if(_loc4_ > 0 && _loc3_ > 0)
  102.       {
  103.          _loc2_ = "nw";
  104.       }
  105.       else if(_loc4_ < 0 && _loc3_ > 0)
  106.       {
  107.          _loc2_ = "ne";
  108.       }
  109.       else if(_loc4_ < 0 && _loc3_ < 0)
  110.       {
  111.          _loc2_ = "se";
  112.       }
  113.       else if(_loc4_ > 0 && _loc3_ < 0)
  114.       {
  115.          _loc2_ = "sw";
  116.       }
  117.       return _loc2_;
  118.    }
  119.    function GetRandom(l_maxNumber)
  120.    {
  121.       var _loc1_ = null;
  122.       if(l_maxNumber > 0)
  123.       {
  124.          _loc1_ = Math.floor(Math.random() * l_maxNumber) + 1;
  125.       }
  126.       else
  127.       {
  128.          _loc1_ = 0;
  129.       }
  130.       return _loc1_;
  131.    }
  132.    function GetRandomB(l_minVal, l_maxVal)
  133.    {
  134.       return l_minVal + Math.floor(Math.random() * (l_maxVal + 1 - l_minVal));
  135.    }
  136. }
  137.