コード例 #1
0
    Vector2 FindEndPosition(bool[,] _mazeMap)
    {
        var _pos = Vector2.zero;

        lastDistance = 0;

        for (int x = 0; x < _mazeMap.GetLength(0); x++)
        {
            for (int y = 0; y < _mazeMap.GetLength(1); y++)
            {
                if (_mazeMap[x, y])
                {
                    var _c = TileWorldNeighbourCounter.CountCrossNeighbours(_mazeMap, x, y, 1, true, false);


                    if (_c == 3)
                    {
                        // we have found an end position
                        // check the distance from this position to start position
                        dist = Vector2.Distance(startPosition, new Vector2(x, y));
                        if (dist > lastDistance)
                        {
                            _pos         = new Vector2(x, y);
                            lastDistance = dist;
                        }
                    }
                }
            }
        }

        return(_pos);
    }
コード例 #2
0
    //Do Simulation steps
    //-------------------
    bool[,] DoSimulationStep(bool[,] oldMap, TileWorldConfiguration _config)
    {
        bool[,] newMap = new bool[_config.global.width, _config.global.height];

        //Loop over each row and column of the map
        for (int x = 0; x < oldMap.GetLength(0); x++)
        {
            for (int y = 0; y < oldMap.GetLength(1); y++)
            {
                int nbs = TileWorldNeighbourCounter.CountAllNeighbours(oldMap, x, y, 1, true);
                //The new value is based on our simulation rules
                //First, if a cell is alive but has too few neighbours, kill it.
                if (oldMap[x, y])
                {
                    if (nbs < _config.cellularAlgorithm.deathLimit)
                    {
                        newMap[x, y] = false;
                    }
                    else
                    {
                        newMap[x, y] = true;
                    }
                    //make sure the cavern is always closed on the border edges
                    if (_config.global.invert)
                    {
                        if (x < 1 || x >= _config.global.width - 1 || y >= _config.global.height - 1 || y < 1)
                        {
                            newMap[x, y] = true;
                        }
                    }
                }
                //Otherwise, if the cell is dead now, check if it has the right number of neighbours to be 'born'
                else
                {
                    if (nbs > _config.cellularAlgorithm.birthLimit)
                    {
                        newMap[x, y] = true;
                    }
                    else
                    {
                        newMap[x, y] = false;
                    }
                    //make sure the cavern is always closed on the border edges
                    if (_config.global.invert)
                    {
                        if (x < 1 || x >= _config.global.width - 1 || y >= _config.global.height - 1 || y < 1)
                        {
                            newMap[x, y] = true;
                        }
                    }
                }
            }
        }

        return(newMap);
    }
コード例 #3
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);
    }
コード例 #4
0
    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);
    }