Example #1
0
        public static void PlaceWalls()
        {
            BoundsInt Bounds = DungeonUtility.GetTilemap().cellBounds;

            TileBase[]        allTiles         = DungeonUtility.GetTilemap().GetTilesBlock(Bounds);
            List <CustomTile> tilesWithinRange = new List <CustomTile>();
            TileHolder        tileHolder       = TileManager.GetTileHolder(TileType.Wall);

            for (int x = 0; x < Bounds.size.x; x++)
            {
                for (int y = 0; y < Bounds.size.y; y++)
                {
                    float randomFreq = Random.Range(1, tileHolder.Tiles.OrderByDescending(t => t.PickChance).First().PickChance);
                    tilesWithinRange = tileHolder.Tiles.Where(t => t.PickChance >= randomFreq).ToList();
                    TileBase tile = allTiles[x + y * Bounds.size.x];
                    int      tempTileIndex;
                    tempTileIndex = Random.Range(0, tilesWithinRange.Count);
                    Vector3Int pos = new Vector3Int(x, y, 0);
                    if (tile == null)
                    {
                        TileManager.PlaceTile(pos, tempTileIndex, null, m_walls, tilesWithinRange[tempTileIndex], DictionaryType.Walls);
                        Tile tileT = m_walls.GetTile <Tile>(pos);
                        if (tilesWithinRange[tempTileIndex].SpriteVariations.Length > 0)
                        {
                            Sprite sT = tilesWithinRange[tempTileIndex].SpriteVariations[Random.Range(0, tilesWithinRange[tempTileIndex].SpriteVariations.Length)];
                            if (sT != null)
                            {
                                tileT.sprite = sT;
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        public static void PlaceFloorTile(Vector2Int _buildPoint)
        {
            Vector3Int t = new Vector3Int(_buildPoint.x, _buildPoint.y, 0);

            if (!TileManager.GetTileDictionaryFloor().ContainsKey(t))
            {
                TileHolder        tileHolder       = TileManager.GetTileHolder(TileType.Floor);
                float             randomFreq       = Random.Range(1, tileHolder.Tiles.OrderByDescending(t => t.PickChance).First().PickChance);
                List <CustomTile> tilesWithinRange = new List <CustomTile>();
                tilesWithinRange = tileHolder.Tiles.Where(t => t.PickChance >= randomFreq).ToList();
                int tempTileIndex;
                tempTileIndex = Random.Range(0, tilesWithinRange.Count);
                TileManager.PlaceTile(t, tempTileIndex, null, DungeonUtility.GetTilemap(), tilesWithinRange[tempTileIndex], DictionaryType.Floor);

                m_floorPositions.Add(t);
                Tile tileT = DungeonUtility.GetTilemap().GetTile <Tile>(t);
                if (tilesWithinRange[tempTileIndex].SpriteVariations.Length > 0)
                {
                    Sprite sT = tilesWithinRange[tempTileIndex].SpriteVariations[Random.Range(0, tilesWithinRange[tempTileIndex].SpriteVariations.Length)];
                    if (sT != null)
                    {
                        tileT.sprite = sT;
                    }
                }
            }
        }
Example #3
0
 /// <summary>
 /// Used to check tiles around a given wall
 /// </summary>
 public static void TileCheckEmpty(Vector3Int _pos1, Vector3Int _pos2, int _indexRoom, int _indexWall)
 {
     if (DungeonUtility.GetTilemap().GetTile(_pos1) == null && DungeonUtility.GetTilemap().GetTile(_pos2) == null)
     {
         TileManager.ChangeTilePiece(m_rooms[_indexRoom].WallPositions[_indexWall], 0, TileType.Wall, DungeonUtility.GetTilemap());
     }
 }
Example #4
0
        public static void Circle(int _startAmount, int _middleAmount)
        {
            Vector2Int        startPoint   = new Vector2Int(DungeonUtility.GetBuildPoint().x, DungeonUtility.GetBuildPoint().y);
            List <Vector2Int> CirclePoints = new List <Vector2Int>();

            CircleRightSide(CirclePoints, _startAmount, startPoint, _middleAmount);
            CircleLeftSide(CirclePoints, startPoint, _middleAmount);
        }
Example #5
0
 public static void Square()
 {
     for (int i = 0; i < WallGen.GetWallDimensions().x + 1; ++i)
     {
         for (int a = 0; a < WallGen.GetWallDimensions().y; ++a)
         {
             Vector2Int pos = new Vector2Int(DungeonUtility.GetBuildPoint().x + i, DungeonUtility.GetBuildPoint().y + a);
             AddToFloorTilePositions(pos);
         }
     }
 }
Example #6
0
 public static void RemoveRoom()
 {
     for (int i = 0; i < m_rooms.Count; ++i)
     {
         for (int w = 0; w < m_rooms[i].WallPositions.Count; ++w)
         {
             DungeonUtility.GetTilemap().SetTile(m_rooms[i].WallPositions[w], null);
             m_rooms[i].WallPositions.RemoveAt(w);
         }
     }
 }
Example #7
0
        public static void PlaceDoor(int _index)
        {
            int        randomPosChoice = Random.Range(0, RoomManager.GetAllRooms()[_index].WallPositions.Count);
            Vector3Int randomWallPos   = RoomManager.GetAllRooms()[_index].WallPositions[randomPosChoice];

            DungeonUtility.AddDoorPosition(randomWallPos);
            RoomManager.GetAllRooms()[_index].DoorPositions.Add(randomWallPos);
            TileManager.ChangeTilePiece(randomWallPos, 0, TileType.Door, DungeonUtility.GetTilemap());

            //   RoomManager.GetAllRooms()[_index].WallPositions.RemoveAt(randomPosChoice);
        }
Example #8
0
        static void BuildPathTile(Vector3Int _pos)
        {
            TileHolder        tileHolder       = TileManager.GetTileHolder(TileType.Path);
            float             randomFreq       = Random.Range(1, tileHolder.Tiles.OrderByDescending(t => t.PickChance).First().PickChance);
            List <CustomTile> tilesWithinRange = new List <CustomTile>();

            tilesWithinRange = tileHolder.Tiles.Where(t => t.PickChance >= randomFreq).ToList();
            int tempTileIndex;

            tempTileIndex = Random.Range(0, tilesWithinRange.Count);
            TileManager.PlaceTile(_pos, tempTileIndex, WallGen.GetTilemap(), DungeonUtility.GetTilemap(), tilesWithinRange[tempTileIndex], DictionaryType.Floor);
        }
Example #9
0
 public static void TileCheckNotEmpty(Vector3Int _pos1, Vector3Int _pos2, Vector3Int _pos3, Vector3Int _pos4, int _indexRoom, int _indexWall, string _tileName)
 {
     if (DungeonUtility.GetTilemap().GetTile(_pos1) != null && DungeonUtility.GetTilemap().GetTile(_pos2) != null && DungeonUtility.GetTilemap().GetTile(_pos3) != null && DungeonUtility.GetTilemap().GetTile(_pos4) != null)
     {
         if (DungeonUtility.GetTilemap().GetTile(_pos1).name == _tileName && DungeonUtility.GetTilemap().GetTile(_pos2).name == _tileName)
         {
             TileManager.ChangeTilePiece(m_rooms[_indexRoom].WallPositions[_indexWall], 0, TileType.Floor, DungeonUtility.GetTilemap());
         }
         if (DungeonUtility.GetTilemap().GetTile(_pos3).name == _tileName && DungeonUtility.GetTilemap().GetTile(_pos4).name == _tileName)
         {
             TileManager.ChangeTilePiece(m_rooms[_indexRoom].WallPositions[_indexWall], 0, TileType.Floor, DungeonUtility.GetTilemap());
         }
     }
 }
Example #10
0
        public static void TShape(int _stemWidth, int _stemHeight, int _roomLength, int _roomHeight, int _directionIndex)
        {
            for (int i = 0; i < _stemWidth + 1; ++i)
            {
                for (int a = 0; a < _stemHeight; ++a)
                {
                    Vector2Int pos = new Vector2Int(DungeonUtility.GetBuildPoint().x + i, DungeonUtility.GetBuildPoint().y + a);
                    AddToFloorTilePositions(pos);
                }
            }
            for (int i = 0; i < _roomLength + 1; ++i)
            {
                for (int a = 0; a < _roomHeight; ++a)
                {
                    switch (_directionIndex)
                    {
                    case 0:    //Right
                        Vector2Int pos = ShapeDirectionVector(_stemWidth + i, ((_stemHeight - _roomHeight) / 2) + a);
                        AddToFloorTilePositions(pos);
                        break;

                    case 1:    //Left
                        Vector2Int pos2 = ShapeDirectionVector((_stemWidth - _roomHeight) / 2 - i, ((_stemHeight - _roomHeight) / 2) + a);
                        AddToFloorTilePositions(pos2);
                        break;

                    case 2:    //Up
                        Vector2Int pos3  = ShapeDirectionVector(_stemWidth / 2 - i, _stemHeight + a);
                        Vector2Int pos3a = ShapeDirectionVector(_stemWidth / 2 + i, _stemHeight + a);
                        AddToFloorTilePositions(pos3);
                        AddToFloorTilePositions(pos3a);
                        break;

                    case 3:    //Down
                        Vector2Int pos4  = ShapeDirectionVector(_stemWidth / 2 - i, a);
                        Vector2Int pos4a = ShapeDirectionVector(_stemWidth / 2 + i, a);
                        AddToFloorTilePositions(pos4);
                        AddToFloorTilePositions(pos4a);
                        break;
                    }
                }
            }
        }
Example #11
0
        static Vector2Int ShapeDirectionVector(int _roomLength, int _roomHeight)
        {
            Vector2Int pos = new Vector2Int(DungeonUtility.GetBuildPoint().x + _roomLength, DungeonUtility.GetBuildPoint().y + _roomHeight);

            return(pos);
        }
Example #12
0
        static void BuildToRoom()
        {
            int xAmount = m_startPos.x - m_endPos.x;
            int yAmount = m_startPos.y - m_endPos.y;

            if (xAmount < 0)
            {
                for (int x = 0; x > xAmount; --x)//Left
                {
                    if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - x, m_startPos.y, 0)) == null)
                    {
                        BuildPathTile(new Vector3Int(m_startPos.x - x, m_startPos.y, 0));
                    }
                }
            }
            else if (xAmount > 0)
            {
                for (int x = 0; x < xAmount; ++x)//Right
                {
                    if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - x, m_startPos.y, 0)) == null)
                    {
                        BuildPathTile(new Vector3Int(m_startPos.x - x, m_startPos.y, 0));
                    }
                    if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - x, m_startPos.y, 0)) != null)
                    {
                        if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - x, m_startPos.y, 0)).name.Contains("Wall"))
                        {
                            BuildPathTile(new Vector3Int(m_startPos.x - x, m_startPos.y, 0));
                        }
                    }
                }
            }
            if (yAmount < 0)
            {
                for (int y = 0; y > yAmount; --y)
                {
                    if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y, 0)) == null)
                    {
                        BuildPathTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y, 0));
                    }
                    if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y - 1, 0)) != null)
                    {
                        if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y - 1, 0)).name.Contains("Wall"))
                        {
                            TileManager.RemoveTilePiece(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y - 1, 0), DungeonUtility.GetTilemap());

                            if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y - 2, 0)) == null)
                            {
                                BuildPathTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y - 1, 0));
                            }
                            else
                            {
                                BuildPathTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y - 1, 0));
                            }
                        }
                    }
                }
            }
            else
            {
                if (yAmount > 0)
                {
                    for (int y = 0; y < yAmount; ++y)
                    {
                        if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x + -xAmount, m_startPos.y - y, 0)) == null)
                        {
                            BuildPathTile(new Vector3Int(m_startPos.x + -xAmount, m_startPos.y - y, 0));
                        }
                        if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x + -xAmount, m_startPos.y - y + 1, 0)) != null)
                        {
                            if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x + -xAmount, m_startPos.y - y + 1, 0)).name.Contains("Wall"))
                            {
                                TileManager.RemoveTilePiece(new Vector3Int(m_startPos.x + -xAmount, m_startPos.y - y + 1, 0), DungeonUtility.GetTilemap());
                                if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y + 2, 0)) == null)
                                {
                                    BuildPathTile(new Vector3Int(m_startPos.x + -xAmount, m_startPos.y - y + 1, 0));
                                }
                                else
                                {
                                    BuildPathTile(new Vector3Int(m_startPos.x + -xAmount, m_startPos.y - y + 1, 0));
                                }
                            }
                        }
                    }
                }
            }
        }
Example #13
0
 public static void PlacePositions(int _index)
 {
     m_roomsToConnect.Add(DungeonUtility.GetAllPathPoints()[Random.Range(0, DungeonUtility.GetAllPathPoints().Count)]);
 }