Exemplo n.º 1
0
 public void InitializeCustomPositions(Dictionary <Vector3Int, int> _map, advancedSurface _surface)
 {
     foreach (Vector3Int p in surfacesData[_surface.TargetSurfaceIndex]._positions)
     {
         _map[new Vector3Int(p.x, p.y, 0)] = Random.Range(1, 101) < _surface.wallChance ? 1 : 0;
     }
 }
Exemplo n.º 2
0
        public void StartSimulation(int repeatNumber)
        {
            wallsMap.ClearAllTiles();
            groundMap.ClearAllTiles();
            mapWidth  = _newGenProperties.tileMapSize.x;
            mapHeight = _newGenProperties.tileMapSize.y;

            if (map == null)
            {
                map = new int[mapWidth, mapHeight];
                advancedSurface surf = new advancedSurface();
                InitializePositions(map, true, surf);
            }
            for (int i = 0; i < repeatNumber; i++)
            {
                advancedSurface surf = new advancedSurface();
                map = GenerateTilePosition(map, true, surf);
            }
            for (int x = 0; x < mapWidth; x++)
            {
                for (int y = 0; y < mapHeight; y++)
                {
                    if (map[x, y] == 1)
                    {
                        wallsMap.SetTile(new Vector3Int(-x + mapWidth / 2, -y + mapHeight / 2, 0), walTile);
                        wallTiles.Add(new Vector3Int(-x + mapWidth / 2, -y + mapHeight / 2, 0));
                    }
                    CreatedTiles.Add(new Vector3Int(-x + mapWidth / 2, -y + mapHeight / 2, 0));
                }
            }
            SetGroundTiles();
            CreateWallValues();
            FindMinMaxValues();
        }
Exemplo n.º 3
0
        public void LoadParameters()
        {
            walTile                       = MapProperties.wallTile;
            groundTile                    = MapProperties.groundTile;
            burnedGroundTile              = MapProperties.burnedGroundTile;
            generationType                = MapProperties.worldGenerationType;
            wallsHealth                   = MapProperties.wallsHealth;
            _newGenProperties.wallChance  = MapProperties.wallChance;
            _newGenProperties.filled      = MapProperties.filled;
            _newGenProperties.empty       = MapProperties.empty;
            _newGenProperties.repeatCount = MapProperties.repeatCount;
            _newGenProperties.tileMapSize = MapProperties.tileMapSize;
            Enemies                       = MapProperties.Enemies;
            enemyAmount                   = MapProperties.enemyAmount;
            _oldGenProperties.TileAmount  = MapProperties.tileAmount;
            TileSize                      = 1;
            _oldGenProperties.chanceUp    = MapProperties.chanceUp;
            _oldGenProperties.chanceRight = MapProperties.chanceRight;
            _oldGenProperties.chanceDown  = MapProperties.chanceDown;
            _oldGenProperties.ExtraWallsX = MapProperties.ExtraWallsX;
            _oldGenProperties.ExtraWallsY = MapProperties.ExtraWallsY;

            ObjectsSpawner = MapProperties.spawner;
            if (ObjectsSpawner.Count != 0)
            {
                for (int i = 0; i < MapProperties.spawner.Count; i++)
                {
                    if (ObjectsSpawner[i].enableSpawner)
                    {
                        objToSpawn spawner = ObjectsSpawner[i];
                        if (!string.IsNullOrEmpty(spawner._tileMapName))
                        {
                            spawner._Map = GameObject.Find(spawner._tileMapName).GetComponent <Tilemap>();
                            if (spawner._Map)
                            {
                                ObjectsSpawner[i] = spawner;
                            }
                        }
                    }
                }
            }
            advanceSurfacesSettings = new List <advancedSurface>();
            advanceSurfacesSettings = MapProperties.extraSurface;
            for (int k = 0; k < advanceSurfacesSettings.Count; k++)
            {
                if (advanceSurfacesSettings[k].enableSurface)
                {
                    advancedSurface s = new advancedSurface();
                    s = advanceSurfacesSettings[k];
                    if (!s._Map)
                    {
                        s._Map = GameObject.Find(s._tileMapName).GetComponent <Tilemap>();
                        advanceSurfacesSettings[k] = s;
                    }
                }
            }
        }
Exemplo n.º 4
0
 public void InitializePositions(int[,] _map, bool isMain, advancedSurface _surface)
 {
     for (int x = 0; x < mapWidth; x++)
     {
         for (int y = 0; y < mapHeight; y++)
         {
             if (isMain)
             {
                 _map[x, y] = Random.Range(1, 101) < _newGenProperties.wallChance ? 1 : 0;
             }
             else
             {
                 _map[x, y] = Random.Range(1, 101) < _surface.wallChance ? 1 : 0;
             }
         }
     }
 }
Exemplo n.º 5
0
        public void StartExtraSurfaceSimulation()
        {
            //if (curentMap)
            //{
            if (advanceSurfacesSettings.Count != 0)
            {
                for (int k = 0; k < advanceSurfacesSettings.Count; k++)
                {
                    if (!string.IsNullOrEmpty(advanceSurfacesSettings[k]._tileMapName))
                    {
                        Tilemap kra = GameObject.Find(advanceSurfacesSettings[k]._tileMapName).GetComponent <Tilemap>();
                        if (kra)
                        {
                            advancedSurface tempsurf = advanceSurfacesSettings[k];
                            tempsurf._Map = kra;
                            advanceSurfacesSettings[k] = tempsurf;
                        }
                    }
                }
            }

            //}
            if (advanceSurfacesSettings.Count != 0)
            {
                //LoadParameters();
                if (!MapProperties.customMap)
                {
                    ClearSurfaces();
                }

                foreach (var surface in advanceSurfacesSettings)
                {
                    if (surface.enableSurface)
                    {
                        //don't forget to manage this problem.
                        if (!MapProperties.customMap)
                        {
                            FillIntList();
                        }
                        StartExampleSimulation(surface.repeatCount, surface._Map, surface._Tile, surface._tempIntMap, surface);
                    }
                }

                SetSurfacesTiles();
            }
        }
Exemplo n.º 6
0
 public void ClearSurfaces()
 {
     LoadParameters();
     foreach (var _surface in advanceSurfacesSettings)
     {
         if (_surface.enableSurface)
         {
             if (_surface._Map)
             {
                 _surface._Map.ClearAllTiles();
             }
         }
     }
     for (int i = 0; i < advanceSurfacesSettings.Count; i++)
     {
         advancedSurface s = advanceSurfacesSettings[i];
         s._tempIntMap = new List <Vector3Int>();
         advanceSurfacesSettings[i] = s;
     }
 }
Exemplo n.º 7
0
        public int[,] GenerateTilePosition(int[,] oldMap, bool isMainSimulation, advancedSurface _surface)
        {
            int[,] newMap = new int[mapWidth, mapHeight];
            int       neighbours;
            BoundsInt bounds = new BoundsInt(-1, -1, 0, 3, 3, 1);

            for (int x = 0; x < mapWidth; x++)
            {
                for (int y = 0; y < mapHeight; y++)
                {
                    neighbours = 0;

                    foreach (Vector3Int position in bounds.allPositionsWithin)
                    {
                        if (position.x == 0 && position.y == 0)
                        {
                            continue;
                        }
                        if (isMainSimulation)
                        {
                            if (x + position.x >= 0 && x + position.x < mapWidth && y + position.y >= 0 && y + position.y < mapHeight)
                            {
                                neighbours += oldMap[x + position.x, y + position.y];
                            }
                            else
                            {
                                neighbours++;
                            }
                        }
                        else
                        {
                            if (x + position.x >= 0 && x + position.x < mapWidth && y + position.y >= 0 && y + position.y < mapHeight)
                            {
                                neighbours += oldMap[x + position.x, y + position.y];
                            }
                        }
                    }
                    if (isMainSimulation)
                    {
                        if (oldMap[x, y] == 1)
                        {
                            if (neighbours < _newGenProperties.empty)
                            {
                                newMap[x, y] = 0;
                            }
                            else
                            {
                                newMap[x, y] = 1;
                            }
                        }
                        if (oldMap[x, y] == 0)
                        {
                            if (neighbours > _newGenProperties.filled)
                            {
                                newMap[x, y] = 1;
                            }
                            else
                            {
                                newMap[x, y] = 0;
                            }
                        }
                    }
                    else
                    {
                        if (oldMap[x, y] == 1)
                        {
                            if (neighbours < _surface.empty)
                            {
                                newMap[x, y] = 0;
                            }
                            else
                            {
                                newMap[x, y] = 1;
                            }
                        }
                        if (oldMap[x, y] == 0)
                        {
                            if (neighbours > _surface.filled)
                            {
                                newMap[x, y] = 1;
                            }
                            else
                            {
                                newMap[x, y] = 0;
                            }
                        }
                    }
                }
            }
            return(newMap);
        }
Exemplo n.º 8
0
        public void StartExampleSimulation(int repeatNumber, Tilemap exMap, TileBase exTile, List <Vector3Int> exIntMap, advancedSurface _surface)
        {
            if (exMap)
            {
                exMap.ClearAllTiles();
            }

            Dictionary <Vector3Int, int> values = new Dictionary <Vector3Int, int>(surfacesData[_surface.TargetSurfaceIndex]._positions.Count);

            InitializeCustomPositions(values, _surface);
            for (int i = 0; i < repeatNumber; i++)
            {
                values = GenerateCustomTilePosition(values, _surface);
            }
            foreach (Vector3Int item in surfacesData[_surface.TargetSurfaceIndex]._positions)
            {
                if (values[item] == 1)
                {
                    exIntMap.Add(new Vector3Int(item.x, item.y, 0));
                }
            }
        }
Exemplo n.º 9
0
        public Dictionary <Vector3Int, int> GenerateCustomTilePosition(Dictionary <Vector3Int, int> oldMap, advancedSurface _surface)
        {
            Dictionary <Vector3Int, int> newMap = new Dictionary <Vector3Int, int>(surfacesData[_surface.TargetSurfaceIndex]._positions.Count);
            int       neighbours;
            BoundsInt bounds = new BoundsInt(-1, -1, 0, 3, 3, 1);

            foreach (Vector3Int XYPos in surfacesData[_surface.TargetSurfaceIndex]._positions)
            {
                neighbours = 0;
                foreach (Vector3Int position in bounds.allPositionsWithin)
                {
                    if (position.x == 0 && position.y == 0)
                    {
                        continue;
                    }

                    if (oldMap.ContainsKey(new Vector3Int(XYPos.x + position.x, XYPos.y + position.y, 0)))
                    {
                        neighbours += oldMap[new Vector3Int(XYPos.x + position.x, XYPos.y + position.y, 0)];
                    }
                }
                if (oldMap[new Vector3Int(XYPos.x, XYPos.y, 0)] == 1)
                {
                    if (neighbours < _surface.empty)
                    {
                        newMap[new Vector3Int(XYPos.x, XYPos.y, 0)] = 0;
                    }
                    else
                    {
                        newMap[new Vector3Int(XYPos.x, XYPos.y, 0)] = 1;
                    }
                }
                if (oldMap[new Vector3Int(XYPos.x, XYPos.y, 0)] == 0)
                {
                    if (neighbours > _surface.filled)
                    {
                        newMap[new Vector3Int(XYPos.x, XYPos.y, 0)] = 1;
                    }
                    else
                    {
                        newMap[new Vector3Int(XYPos.x, XYPos.y, 0)] = 0;
                    }
                }
            }
            return(newMap);
        }