Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1.  /// <summary>
  2.         /// This function calculates the bitmask value for the tile, allowing us to assign is a tile
  3.         /// </summary>
  4.         /// <param X pos of tile on grid="x"></param>
  5.         /// <param y pos of tile on grid="z"></param>
  6.         /// <returns></returns>
  7.         private int calculateTileBitmaskValue(int x,int z)
  8.         {
  9.             //Begin by assuming tile is water
  10.             int bitmaskValue = 15;
  11.  
  12.             float tileHeight = terrainHeights[x, z];
  13.            
  14.             if (getIsLand(tileHeight))
  15.             {
  16.                 //The tile is land, let's check surrounding neighbours.
  17.                 bool north_tile = getIsLand(terrainHeights[x, z - 1]);
  18.                 bool east_tile = getIsLand(terrainHeights[x+1, z]);
  19.                 bool west_tile = getIsLand(terrainHeights[x-1, z]);
  20.                 bool south_tile = getIsLand(terrainHeights[x, z + 1]);
  21.  
  22.                 //Calculate our bitmask value from our boolean values for each direction:
  23.                 bitmaskValue = ((1 * Convert.ToInt32(north_tile)) + (2 * Convert.ToInt32(west_tile))
  24.                     + (4 * Convert.ToInt32(east_tile)) + (8 * Convert.ToInt32(south_tile)));
  25.  
  26.             }
  27.  
  28.             return bitmaskValue;
  29.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement