Advertisement
kemonologic

fCollision_Grid_BakeLayers

Dec 13th, 2019
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @func fCollision_Grid_BakeLayers
  2.  
  3. var _tileLayers = fEditor_Layer_Get_TileLayerList();
  4. var _grid = oLayerController.collisionGrid;
  5. ds_grid_clear(_grid,0);
  6.  
  7. for (var l = 0; l < ds_list_size(_tileLayers); l++){
  8.     var _layer = _tileLayers[| l];
  9.     if (!fEditor_Layer_Get_IsLayerCollision(_layer)){
  10.         continue;
  11.     }
  12.    
  13.     var _tilemapList = fEditor_Layer_Get_ElementsOfType(_collisionLayerMap,layerelementtype_tilemap);
  14.    
  15.     for (var tm = 0; tm < ds_list_size(_tilemapList); tm++){
  16.         var _tilemap = _tilemapList[| tm];
  17.         var _tilemapDims =  [
  18.                                     tilemap_get_x(_tilemap),
  19.                                     tilemap_get_y(_tilemap),
  20.                                     tilemap_get_width(_tilemap),
  21.                                     tilemap_get_height(_tilemap)];
  22.                                    
  23.         var _tilesProcessed = 0;
  24.         var _tilesTotal = fEditor_Layer_Tilemap_NumTiles_Get(_tilemap);
  25.         if (_tilesTotal == 0){
  26.                 continue;
  27.         }
  28.         if (_tilemapDims[rectWH.w] % TILE_SIZE != 0 || _tilemapDims[rectWH.h] % TILE_SIZE != 0){
  29.                 fTrace("[WARN] fCollision_Grid_BakeLayers: Tilemap offset is not divisible by tile size!");
  30.         }
  31.         if (_tilemapDims[rectWH.x] + _tilemapDims[rectWH.w] >= ds_grid_width(oLayerController.collisionGrid) ||
  32.              _tilemapDims[rectWH.y] + _tilemapDims[rectWH.h] >= ds_grid_height(oLayerController.collisioNGrid)){
  33.                 fTrace("[WARN] fCollision_Grid_BakeLayers: Tilemap size exceeds collision grid size for some reason!");
  34.         }
  35.        
  36.         var _gridOffsetX = _tilemapDims[rectWH.x];
  37.         var _gridOffsetY = _tilemapDims[rectWH.y];
  38.        
  39.         for (var ty = 0; ty < _tilemapDims[rectWH.h]; ty++){
  40.             if (_tilesProcessed == _tilesTotal){
  41.                 break;
  42.             }
  43.             for (var tx = 0; tx < _tilemapDims[rectWH.w]; tx++){
  44.                 if (_tilesProcessed == _tilesTotal){
  45.                     break;
  46.                 }
  47.                 var _cellHasTile = !tilemap_tile_empty(_tilemap,tx,ty);
  48.                 _grid[# tx + _gridOffsetX, ty + _gridOffsetY] |= _cellHasTile;
  49.                 _tilesProcessed += _cellHasTile;
  50.             }
  51.         }
  52.     }
  53.     ds_list_destroy(_tilemapList);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement