Example #1
0
        public void SetDoors(MapTilemaps tilemaps, int x, int y, Vector3Int center, RoomSizeInfo roomSizeInfo,
                             RoomType[,] mapRoomMatrix)
        {
            if (x > 0 && mapRoomMatrix[x - 1, y] != RoomType.None)
            {
                SetDoor(tilemaps, x - 1, y, x, y,
                        center - new Vector3Int(roomSizeInfo.roomWidth / 2, 0, 0), DoorController.DoorType.Horizontal);
            }

            if (x < _map.Width - 1 && mapRoomMatrix[x + 1, y] != RoomType.None)
            {
                SetDoor(tilemaps, x, y, x + 1, y,
                        center + new Vector3Int(roomSizeInfo.roomWidth / 2, 0, 0), DoorController.DoorType.Horizontal);
            }

            if (y > 0 && mapRoomMatrix[x, y - 1] != RoomType.None)
            {
                SetDoor(tilemaps, x, y - 1, x, y,
                        center - new Vector3Int(0, roomSizeInfo.roomHeight / 2, 0), DoorController.DoorType.Vertical);
            }

            if (y < _map.Height - 1 && mapRoomMatrix[x, y + 1] != RoomType.None)
            {
                SetDoor(tilemaps, x, y, x, y + 1,
                        center + new Vector3Int(0, roomSizeInfo.roomHeight / 2, 0), DoorController.DoorType.Vertical);
            }
        }
Example #2
0
        private IEnumerable <Vector3Int> SetFloor(MapTilemaps tilemaps, Vector3Int center, RoomSizeInfo roomSizeInfo)
        {
            var tiles = new List <Vector3Int>();
            var start = new Vector3Int(center.x - roomSizeInfo.roomWidth / 2, center.y - roomSizeInfo.roomHeight / 2,
                                       center.z);

            for (var x = 1; x < roomSizeInfo.roomWidth - 1; x++)
            {
                for (var y = 1; y < roomSizeInfo.roomHeight - 1; y++)
                {
                    //Debug.Log("Set floor tile at: " + (start + new Vector3Int(x, y, 0)));
                    var pos     = start + new Vector3Int(x, y, 0);
                    var newTile = _mapSettingsData.GetFloorTile();
                    tilemaps.FloorTilemap.SetTile(pos, newTile);
                    tiles.Add(pos);
                }
            }

            return(tiles);
        }
Example #3
0
        private IEnumerable <Vector3Int> SetWalls(MapTilemaps tilemaps, Vector3Int center, RoomSizeInfo roomSizeInfo, TileBase tile)
        {
            var tiles = new List <Vector3Int>();
            var start = new Vector3Int(center.x - roomSizeInfo.roomWidth / 2, center.y - roomSizeInfo.roomHeight / 2,
                                       center.z);

            for (var x = 0; x < roomSizeInfo.roomWidth; x++)
            {
                var bottom = start + new Vector3Int(x, 0, 0);
                var top    = start + new Vector3Int(x, roomSizeInfo.roomHeight - 1, 0);

                tilemaps.WallTilemap.SetTile(bottom, tile);
                tilemaps.WallTilemap.SetTile(top, tile);

                tiles.Add(bottom);
                tiles.Add(top);
            }

            for (var y = 0; y < roomSizeInfo.roomHeight; y++)
            {
                var left  = start + new Vector3Int(0, y, 0);
                var right = start + new Vector3Int(roomSizeInfo.roomWidth - 1, y, 0);

                tilemaps.WallTilemap.SetTile(left, tile);
                tilemaps.WallTilemap.SetTile(right, tile);

                tiles.Add(left);
                tiles.Add(right);
            }

            return(tiles);
        }