예제 #1
0
    private void RandomFillMap()
    {
        _map = new int[_width, _height];

        if (_useRandomSeed)
            _seed = System.DateTime.Now.ToString ("yyyyMMddHHmmssffff");

        IndigoRandom ir = new IndigoRandom (_seed);

        for (int x = 0; x < _width; x ++) {
            for (int y = 0; y < _height; y ++) {
                if (x == 0 || x == _width-1 || y == 0 || y == _height -1) {
                    _map[x,y] = 1;
                } else {
                    _map[x,y] = (ir.GetHash (0, 100, x, y) < _randomFillPercent)? 1: 0;
                }
            }
        }
    }
예제 #2
0
    // PRIVATE ////////////////////////////
    private int[,] GenerateHeightMap(int[,] map)
    {
        int[,,] tmpMap = new int[map.GetLength(0), map.GetLength(1), 5];
        IndigoRandom ir = new IndigoRandom (_seed+_seed);

        for (int x = 0; x < map.GetLength(0); x++)
        {
            for (int y = 0; y < map.GetLength(1); y++)
            {
                bool terrainSwitch = false;
                int surrounding = GetSurroundingHeightCount (map, x, y, out terrainSwitch);

                tmpMap [x, y, 0] = 0;
                tmpMap [x, y, 1] = 0;
                tmpMap [x, y, 2] = 0;
                tmpMap [x, y, 3] = 0;
                tmpMap [x, y, 4] = 0;

                // wenn x/y == 0 oder max-width/-height
                // && value == 0
                // --> Ocean

                // wenn summe der umliegenden tiles <= 0
                // --> tile random (-1,0)
                if( !terrainSwitch && surrounding <= 0)
                {
                    tmpMap [x, y, 0] = (ir.GetHash (0, 100, x, y, 0) > 65) ? 1 : 0;

                }

                // wenn > (5-8) && ??
                // --> tile random (0,+1)
                if( !terrainSwitch && surrounding > 5)
                {
                    tmpMap [x, y, 1] = (ir.GetHash (0, 100, x, y, 1) > 40) ? 1 : 0;
                }

                /*
                if (x >= borderSize && x < _width + borderSize && y >= borderSize && y < _height + borderSize) {

                } else {

                }
                */
            }
        }

        _heightMap = map;
        for (int heightLevel = 0; heightLevel < 5; heightLevel++)
        {
            int[,] smoothedTmpMap = ExtractHeightLayer(tmpMap, heightLevel);

            for (int i = 0; i < 5; i++)
            {
                smoothedTmpMap = SmoothMap (smoothedTmpMap, 4);
            }

            for (int x = 0; x < map.GetLength (0); x++)
            {
                for (int y = 0; y < map.GetLength (1); y++)
                {
                    if(heightLevel <= 0)
                        _heightMap [x, y] -= smoothedTmpMap [x, y];
                    else
                        _heightMap [x, y] += smoothedTmpMap [x, y];
                }
            }
        }

        return _heightMap;
    }