Ejemplo n.º 1
0
        private void GenerateLayer(TilemapData tilemapData, GroundLayer groundLayer, int leftBorder, int rightBorder, int minimumDepth, int maximumDepth)
        {
            List <float> resourceProbabilities = groundLayer.GetResourceProbabilitiesForGeneration();
            bool         tileSet;
            float        prob;


            for (int x = leftBorder; x < rightBorder; ++x)
            {
                for (int y = minimumDepth; y > maximumDepth; --y)
                {
                    tileSet = false;
                    prob    = Random.Range(0f, 1f);
                    for (int j = 0; j < groundLayer.Resources.Count; ++j)
                    {
                        if (prob <= resourceProbabilities[j])
                        {
                            tilemapData.SetTileId(x, y, groundLayer.Resources[j].Type.Id);
                            tileSet = true;
                            break;
                        }
                    }

                    if (!tileSet)
                    {
                        tilemapData.SetTileId(x, y, groundLayer.DefaultTile.Id);
                    }
                }
            }

            for (int y = minimumDepth; y > (maximumDepth + 1); --y)
            {
                for (int x = leftBorder; x < rightBorder; ++x)
                {
                    prob = Random.Range(0f, 1f);
                    if (prob <= groundLayer.ProbabilityOfEmptySpaces)
                    {
                        tilemapData.SetTileId(x, y, -1);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private void GenerateSurface(TilemapData tilemapData, int leftBorder, int rightBorder, int minimumDepth, int maximumDepth)
 {
     for (int x = leftBorder; x < rightBorder; ++x)
     {
         for (int y = minimumDepth; y > maximumDepth; --y)
         {
             if (_surfaceTilemap.GetTile(new Vector3Int(x, y, 0)) is Tile tile)
             {
                 tilemapData.SetTileId(x, y, _tileIdentifier.Identify(tile.sprite).Id);
             }
         }
     }
 }
Ejemplo n.º 3
0
 public void SetTile(Vector2Int pos, int tileId)
 {
     _data.SetTileId(pos, tileId);
     if (_tilemapLoader.IsTileLoaded(pos))
     {
         Tile tile;
         if (tileId != -1)
         {
             TileType tt = _tileIdentifier.Identify(tileId);
             if (tt != null)
             {
                 tile = _tileIdentifier.Identify(tileId).ClasifiedTiles.FirstOrDefault();
             }
             else
             {
                 tile = null;
             }
         }
         else
         {
             tile = GetTileEdge(pos);
             if (_data.GetTileId(pos + Vector2Int.up) == -1)
             {
                 SetEdge(pos + Vector2Int.up);
             }
             if (_data.GetTileId(pos + Vector2Int.right) == -1)
             {
                 SetEdge(pos + Vector2Int.right);
             }
             if (_data.GetTileId(pos + Vector2Int.down) == -1)
             {
                 SetEdge(pos + Vector2Int.down);
             }
             if (_data.GetTileId(pos + Vector2Int.left) == -1)
             {
                 SetEdge(pos + Vector2Int.left);
             }
         }
         _tilemaps.First(x => x.Item1 <= pos.y).Item2.SetTile((Vector3Int)pos, tile);
     }
 }