Exemple #1
0
 public GlobalMap(IDrawMap drawMap, Dictionary <Point, TileMapData> map, TileFlyweight defaultTile)
 {
     _drawMap     = drawMap;
     _map         = map;
     _defaultTile = defaultTile;
     _vision      = new Dictionary <Point, TileMapData>();
 }
Exemple #2
0
 public TileMapData(TileFlyweight data, int amountResources = -1)
 {
     Data            = data;
     AmountResources = amountResources;
 }
Exemple #3
0
        public Dictionary <Point, TileMapData> GenerateStatic(out TileFlyweight defaultTile)
        {
            var map      = new Dictionary <Point, TileMapData>();
            var data     = Data[0];
            var fwBorder = GetTileFlyweight(data.Border);

            for (int x = 0, xLength = data.SizeMapX; x < xLength; x++)
            {
                map[new Point(x, 0)] = new TileMapData(fwBorder);
                map[new Point(x, data.SizeMapY - 1)] = new TileMapData(fwBorder);
            }

            for (int x = 1, xLength = data.SizeMapY - 1; x < xLength; x++)
            {
                map[new Point(0, x)] = new TileMapData(fwBorder);
                map[new Point(data.SizeMapX - 1, x)] = new TileMapData(fwBorder);
            }

            var fwEmpty = GetTileFlyweight(data.Ground);

            for (int x = 1, xLength = data.SizeMapX - 1; x < xLength; x++)
            {
                for (int y = 1, yLength = data.SizeMapY - 1; y < yLength; y++)
                {
                    map[new Point(x, y)] = new TileMapData(fwEmpty);
                }
            }


            for (int i = 0; i < data.SpawnTile.Length; i++)
            {
                var tile       = data.SpawnTile[i];
                var fwTile     = GetTileFlyweight(tile.Type);
                var xOrigin    = UnityEngine.Random.Range(0f, 100f);
                var yOrigin    = UnityEngine.Random.Range(0f, 100f);
                var lengthLuck = (1 - tile.SpawnValue);
                for (int x = data.SizeMapX - 2; x >= 1; x--)
                {
                    for (int y = data.SizeMapY - 2; y >= 1; y--)
                    {
                        var position = new Point(x, y);

                        if (map[position].Data != fwEmpty)
                        {
                            continue;
                        }

                        var xCoord = xOrigin + (x * tile.ScaleNoise) / data.SizeMapX;
                        var yCoord = yOrigin + (y * tile.ScaleNoise) / data.SizeMapY;

                        var noiseValue = Mathf.PerlinNoise(xCoord, yCoord);
                        //Debug.LogWarning(x + " " + y + " " + noiseValue);
                        if (noiseValue > tile.SpawnValue)
                        {
                            map[position] = new TileMapData(fwTile, (int)Mathf.Ceil(5 * ((noiseValue - tile.SpawnValue) / lengthLuck)));
                        }
                    }
                }
            }


            defaultTile = ListTiles[indexDefaultTile];
            return(map);
        }