Пример #1
0
    public bool[,] ApplyMask(bool[,] _map, TileWorldCreator _creator, TileWorldConfiguration _config)
    {
        //create a temp map
        bool[,] _tmpMap = new bool[_map.GetLength(0), _map.GetLength(1)];

        //loop through the maps x and y length
        for (int y = 0; y < _map.GetLength(1); y++)
        {
            for (int x = 0; x < _map.GetLength(0); x++)
            {
                //here we are using the TileWorldNeighbourCounter to count
                //the neighbour cells of the current cell from the map.
                int _c = 0;
                _c = TileWorldNeighbourCounter.CountInnerTerrainBlocks(_map, x, y, 1, _config.global.invert);

                //if invert is set to false in the settings of TileWorldCreator
                if (!_config.global.invert)
                {
                    //if the current cell has got 8 neighbours
                    //then the cell is not located on the border of the island
                    if (_c == 8 || _map[x, y])
                    {
                        _tmpMap[x, y] = true;
                    }
                    //else we can be sure that the current cell is a border cell
                    else
                    {
                        _tmpMap[x, y] = false;
                    }
                }
                else
                {
                    //inverted tmpMap values when invert is set to true.
                    if (_c == 8)
                    {
                        _tmpMap[x, y] = false;
                    }
                    else
                    {
                        _tmpMap[x, y] = true;
                    }
                }
            }
        }

        //return the modified map
        return(_tmpMap);
    }
    public bool[,] ApplyMask(bool[,] _map, TileWorldCreator _creator, TileWorldConfiguration _config)
    {
        bool[,] _tmpMap = new bool[_map.GetLength(0), _map.GetLength(1)];

        //get inner terrain cells
        for (int y = 0; y < _map.GetLength(1); y++)
        {
            for (int x = 0; x < _map.GetLength(0); x++)
            {
                int _c = 0;
                _c = TileWorldNeighbourCounter.CountInnerTerrainBlocks(_map, x, y, 1, _config.global.invert);

                if (!_config.global.invert)
                {
                    if (_c == 8)
                    {
                        _tmpMap[x, y] = false;
                    }
                    else
                    {
                        _tmpMap[x, y] = true;
                    }
                }
                else
                {
                    if (_c == 8)
                    {
                        _tmpMap[x, y] = true;
                    }
                    else
                    {
                        _tmpMap[x, y] = false;
                    }
                }
            }
        }

        //get random cells from inner terrain map
        bool[,] _newMap = new bool[_config.global.width, _config.global.height];
        for (int y = 0; y < _map.GetLength(1); y++)
        {
            for (int x = 0; x < _map.GetLength(0); x++)
            {
                float _rnd = Random.Range(0f, 1f);

                if (!_config.global.invert)
                {
                    //invert map if invert ist set to false
                    _newMap[x, y] = true;
                }


                if (_rnd < 0.3f)
                {
                    if (_config.global.invert)
                    {
                        if (_tmpMap[x, y])
                        {
                            _newMap[x, y] = true;
                        }
                    }
                    else
                    {
                        if (!_tmpMap[x, y])
                        {
                            _newMap[x, y] = false;
                        }
                    }
                }
            }
        }

        return(_newMap);
    }