author suo
  import Point = egret . Point ; module FishingJoy { export class NineGridSplitScreenTool { public static firstLineX : number = 0 ; public static secondLineX : number = 0 ; public static firstLineY : number = 0 ; public static secondLineY : number = 0 ; public pic : egret . Shape = new egret . Shape ( ) ; public constructor ( ) { } public static initValue ( ) { let width = ( uniLib . Global . screenWidth + 200 ) / 3 ; let height = ( uniLib . Global . screenHeight + 200 ) / 3 ; this . firstLineX = - 100 + width ; this . firstLineY = - 100 + height ; this . secondLineX = - 100 + width * 2 ; this . secondLineY = - 100 + height * 2 ; } /**
         * 设置在哪一个格子
         */ public static setGridIndex ( gameObj , dic ) { gameObj . clearGridIndex ( ) ; if ( gameObj . isAccurateCollider ) { let len = gameObj . colliderAry . length ; for ( let i = 0 ; i < len ; i ++ ) { let collider = gameObj . colliderAry [ i ] ; this . analyseGridMap ( collider . globePosPoint . x , collider . globePosPoint . y , gameObj , dic ) ; } } else { this . analyseGridMap ( gameObj . x , gameObj . y , gameObj , dic ) ; } } /**
         * 写入字典
         */ public static writeInMap ( gridIndex , gameObj , dic ) { let gameObjAry = dic . get ( gridIndex ) ; if ( gameObjAry == null ) { gameObjAry = new Array < gameObject . GameObjectCollider > ( ) ; dic . set ( gridIndex , gameObjAry ) ; } if ( gameObjAry . indexOf ( gameObj ) == - 1 ) { gameObjAry . push ( gameObj ) ; } } /**
         * 分析在哪个格子里
         */ public static analyseGrid ( gameObj ) { let firstLineX = this . firstLineX ; let secondLineX = this . secondLineX ; let firstLineY = this . firstLineY ; let secondLineY = this . secondLineY ; let x = gameObj . x ; let y = gameObj . y ; if ( UIUtil . inBorder ( x , y ) ) { if ( y < firstLineY ) { if ( x < firstLineX ) { gameObj . pushGridIndex ( Grid . Grid_1 ) ; } else if ( x >= firstLineX && x < secondLineX ) { gameObj . pushGridIndex ( Grid . Grid_2 ) ; } else if ( x >= secondLineX ) { gameObj . pushGridIndex ( Grid . Grid_3 ) ; } } else if ( y < secondLineY && y >= firstLineY ) { if ( x < firstLineX ) { gameObj . pushGridIndex ( Grid . Grid_4 ) ; } else if ( x >= firstLineX && x < secondLineX ) { gameObj . pushGridIndex ( Grid . Grid_5 ) ; } else if ( x >= secondLineX ) { gameObj . pushGridIndex ( Grid . Grid_6 ) ; } } else { if ( x < firstLineX ) { gameObj . pushGridIndex ( Grid . Grid_7 ) ; } else if ( x >= firstLineX && x < secondLineX ) { gameObj . pushGridIndex ( Grid . Grid_8 ) ; } else if ( x >= secondLineX ) { gameObj . pushGridIndex ( Grid . Grid_9 ) ; } } } } /**
         * 分析在哪个格子里
         */ public static analyseGridMap ( x , y , gameObj , dic ) { let firstLineX = this . firstLineX ; let secondLineX = this . secondLineX ; let firstLineY = this . firstLineY ; let secondLineY = this . secondLineY ; if ( UIUtil . inBorder ( x , y ) ) { if ( y < firstLineY ) { if ( x < firstLineX ) { this . writeInMap ( Grid . Grid_1 , gameObj , dic ) ; } else if ( x >= firstLineX && x < secondLineX ) { this . writeInMap ( Grid . Grid_2 , gameObj , dic ) ; } else if ( x >= secondLineX ) { this . writeInMap ( Grid . Grid_3 , gameObj , dic ) ; } } else if ( y < secondLineY && y >= firstLineY ) { if ( x < firstLineX ) { this . writeInMap ( Grid . Grid_4 , gameObj , dic ) ; } else if ( x >= firstLineX && x < secondLineX ) { this . writeInMap ( Grid . Grid_5 , gameObj , dic ) ; } else if ( x >= secondLineX ) { this . writeInMap ( Grid . Grid_6 , gameObj , dic ) ; } } else { if ( x < firstLineX ) { this . writeInMap ( Grid . Grid_7 , gameObj , dic ) ; } else if ( x >= firstLineX && x < secondLineX ) { this . writeInMap ( Grid . Grid_8 , gameObj , dic ) ; } else if ( x >= secondLineX ) { this . writeInMap ( Grid . Grid_9 , gameObj , dic ) ; } } } } } } /**
 * 格子
 */ const enum Grid { Grid_1 = 0 , Grid_2 , Grid_3 , Grid_4 , Grid_5 , Grid_6 , Grid_7 , Grid_8 , Grid_9 }