home *** CD-ROM | disk | FTP | other *** search
- class Utils
- {
- var MAP_WIDTH_CELL = 40;
- var WIDTH_CELL = 70;
- var WIDTH_SCREEN = 400;
- var MAP_SCALE_FACTOR = 24;
- var PARALLAX_SCALE_FACTOR = 16;
- var posCenterScreen = new Object();
- function Utils()
- {
- this.posCenterScreen.x = 400;
- this.posCenterScreen.y = 400;
- }
- function ConvertHitPosToMap(l_coord)
- {
- l_coord.x = - l_coord.x * this.MAP_SCALE_FACTOR + this.posCenterScreen.x;
- l_coord.y = - l_coord.y * this.MAP_SCALE_FACTOR + this.posCenterScreen.y;
- return l_coord;
- }
- function ConvertHitPosToParallax1(l_coord)
- {
- l_coord.x = - l_coord.x * this.PARALLAX_SCALE_FACTOR + this.posCenterScreen.x + 25;
- l_coord.y = - l_coord.y * this.PARALLAX_SCALE_FACTOR;
- return l_coord;
- }
- function ConvertHitPosToParallax2(l_coord)
- {
- l_coord.x = - l_coord.x * this.PARALLAX_SCALE_FACTOR + this.posCenterScreen.x;
- l_coord.y = - l_coord.y * this.PARALLAX_SCALE_FACTOR + this.posCenterScreen.y;
- return l_coord;
- }
- function ConvertHitPosToParallax3(l_coord)
- {
- l_coord.x = - l_coord.x * this.PARALLAX_SCALE_FACTOR + this.posCenterScreen.x;
- l_coord.y = - l_coord.y * this.PARALLAX_SCALE_FACTOR + this.posCenterScreen.y;
- return l_coord;
- }
- function GetAbsDistBetweenObj(l_objA, l_objB)
- {
- var _loc1_ = l_objA.GetStageCoord();
- var _loc2_ = l_objB.GetStageCoord();
- return Math.sqrt((_loc1_.x - _loc2_.x) * (_loc1_.x - _loc2_.x) + (_loc1_.y - _loc2_.y) * (_loc1_.y - _loc2_.y));
- }
- function GetHitZone(l_coord)
- {
- var _loc3_ = l_coord;
- _global.C._parent.ScrollMap.Items.Map.HitContainer.globalToLocal(_loc3_);
- _loc3_.x = Math.ceil(_loc3_.x / this.WIDTH_CELL);
- _loc3_.y = Math.ceil(_loc3_.y / this.WIDTH_CELL);
- return _loc3_;
- }
- function GetMapZone(l_coord)
- {
- var _loc3_ = l_coord;
- _global.C._parent.ScrollMap.Items.Map.HitContainer.globalToLocal(_loc3_);
- _loc3_.x = Math.ceil(_loc3_.x / (this.MAP_WIDTH_CELL / 8));
- _loc3_.y = Math.ceil(_loc3_.y / (this.MAP_WIDTH_CELL / 8));
- return _loc3_;
- }
- function GetDiffZone(l_mainZone, l_secondZone)
- {
- var _loc1_ = new Object();
- _loc1_.x = l_mainZone.x - l_secondZone.x;
- _loc1_.y = l_mainZone.y - l_secondZone.y;
- return _loc1_;
- }
- function GetDirBetweenObject(l_mainObj, l_destObj)
- {
- var _loc5_ = l_mainObj.GetZone();
- var _loc6_ = l_destObj.GetZone();
- var _loc7_ = this.WIDTH_SCREEN / this.MAP_WIDTH_CELL;
- var _loc4_ = _loc5_.x - _loc6_.x;
- var _loc3_ = _loc5_.y - _loc6_.y;
- var _loc2_ = null;
- if(_loc4_ == 0 && _loc3_ == 0)
- {
- _loc2_ = "same";
- }
- else if(_loc4_ == 0)
- {
- if(_loc3_ > 0)
- {
- _loc2_ = "n";
- }
- else
- {
- _loc2_ = "s";
- }
- }
- else if(_loc3_ == 0)
- {
- if(_loc4_ > 0)
- {
- _loc2_ = "w";
- }
- else
- {
- _loc2_ = "e";
- }
- }
- else if(_loc4_ > 0 && _loc3_ > 0)
- {
- _loc2_ = "nw";
- }
- else if(_loc4_ < 0 && _loc3_ > 0)
- {
- _loc2_ = "ne";
- }
- else if(_loc4_ < 0 && _loc3_ < 0)
- {
- _loc2_ = "se";
- }
- else if(_loc4_ > 0 && _loc3_ < 0)
- {
- _loc2_ = "sw";
- }
- return _loc2_;
- }
- function GetRandom(l_maxNumber)
- {
- var _loc1_ = null;
- if(l_maxNumber > 0)
- {
- _loc1_ = Math.floor(Math.random() * l_maxNumber) + 1;
- }
- else
- {
- _loc1_ = 0;
- }
- return _loc1_;
- }
- function GetRandomB(l_minVal, l_maxVal)
- {
- return l_minVal + Math.floor(Math.random() * (l_maxVal + 1 - l_minVal));
- }
- }
-