Exemplo n.º 1
0
        public override void Build(int roomX, int roomY, RoomData roomData, Transform transform)
        {
            PlaceCells(roomData);

            int maximumSize = (int)DungeonManager.Dungeon.MaximumRoomSize;

            for (int x = 0; x < maximumSize; x++)
            {
                for (int y = 0; y < maximumSize; y++)
                {
                    if (_roomCells[x, y] == RoomCellData.Wall)
                    {
                        WallData wallData = _wallVariants.GetRandomElement();
                        Instantiate(wallData.WallTop, new Vector3(transform.position.x + x, transform.position.y + y), transform.rotation, transform);
                        if (y - 1 < 0)
                        {
                            ConnectionType bottomConnectionType = DungeonManager.Dungeon.GetRoomConnection(roomX, roomY - 1).Top;

                            if (bottomConnectionType == ConnectionType.None)
                            {
                                Instantiate(wallData.WallBrick, new Vector3(transform.position.x + x, transform.position.y + y - 0.5f), transform.rotation, transform);
                                Instantiate(_shadow, new Vector3(transform.position.x + x, transform.position.y + y - 1, -1), transform.rotation, transform);
                            }

                            else if (bottomConnectionType == ConnectionType.Wall)
                            {
                                RoomData bottomRoom = DungeonManager.Dungeon.GetRoom(roomX, roomY - 1);
                                if (bottomRoom != null && bottomRoom.Size < DungeonManager.Dungeon.MaximumRoomSize)
                                {
                                    Instantiate(wallData.WallBrick, new Vector3(transform.position.x + x, transform.position.y + y - 0.5f), transform.rotation, transform);
                                    Instantiate(_shadow, new Vector3(transform.position.x + x, transform.position.y + y - 1, -1), transform.rotation, transform);
                                }
                                else if (bottomRoom == null)
                                {
                                    Instantiate(wallData.WallBrick, new Vector3(transform.position.x + x, transform.position.y + y - 0.5f), transform.rotation, transform);
                                    Instantiate(_shadow, new Vector3(transform.position.x + x, transform.position.y + y - 1, -1), transform.rotation, transform);
                                }
                            }
                            else if (roomData.Size == DungeonManager.Dungeon.MaximumRoomSize)
                            {
                                int centerPoint      = (maximumSize - 1) / 2;
                                int connectionOffset = 0;
                                switch (bottomConnectionType)
                                {
                                case ConnectionType.Small:
                                    connectionOffset = 2;
                                    break;

                                case ConnectionType.Medium:
                                    connectionOffset = 3;
                                    break;

                                case ConnectionType.Big:
                                    connectionOffset = 4;
                                    break;
                                }
                                if (x != centerPoint - connectionOffset && x != centerPoint + connectionOffset)
                                {
                                    Instantiate(wallData.WallBrick, new Vector3(transform.position.x + x, transform.position.y + y - 0.5f), transform.rotation, transform);
                                    Instantiate(_shadow, new Vector3(transform.position.x + x, transform.position.y + y - 1, -1), transform.rotation, transform);
                                }
                            }
                        }
                        else if (_roomCells[x, y - 1] != RoomCellData.Wall)
                        {
                            Instantiate(wallData.WallBrick, new Vector3(transform.position.x + x, transform.position.y + y - 0.5f), transform.rotation, transform);
                            Instantiate(_shadow, new Vector3(transform.position.x + x, transform.position.y + y - 1, -1), transform.rotation, transform);
                        }
                    }
                    else if (_roomCells[x, y] == RoomCellData.Floor)
                    {
                        Instantiate(_floorVariants.GetRandomElement(), new Vector3(transform.position.x + x, transform.position.y + y, 1), transform.rotation, transform);

                        List <RoomElementData> possibleElements = roomData.RoomElements.FindAll(t => t.Position.x >= x && t.Position.x < x + 1 && t.Position.y >= y && t.Position.y < y + 1);
                        if (possibleElements.Count > 0)
                        {
                            RoomElementData randomElement = GetRandomElement(possibleElements);
                            if (randomElement != null)
                            {
                                Instantiate(randomElement.GameObject, new Vector3(transform.position.x + randomElement.Position.x, transform.position.y + randomElement.Position.y), transform.rotation, transform);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void BuildOpen(RoomData roomData, Side side, int connectionOffset)
        {
            int maximumSize = (int)DungeonManager.Dungeon.MaximumRoomSize;
            int roomSize    = (int)roomData.Size;
            int offset      = (maximumSize - roomSize) / 2;
            int centerPoint = (maximumSize - 1) / 2;


            switch (side)
            {
            case Side.Top:
                for (int y = maximumSize - offset - 1; y < maximumSize; y++)
                {
                    for (int x = offset; x < maximumSize - offset; x++)
                    {
                        if (_roomCells[x, y] == RoomCellData.None)
                        {
                            if (y == maximumSize - offset - 1)
                            {
                                if (x > centerPoint - connectionOffset && x < centerPoint + connectionOffset)
                                {
                                    _roomCells[x, y] = RoomCellData.Floor;
                                }
                                else
                                {
                                    _roomCells[x, y] = RoomCellData.Wall;
                                }
                            }
                            else
                            {
                                if (x == centerPoint - connectionOffset || x == centerPoint + connectionOffset)
                                {
                                    _roomCells[x, y] = RoomCellData.Wall;
                                }
                                else if (x > centerPoint - connectionOffset && x < centerPoint + connectionOffset)
                                {
                                    _roomCells[x, y] = RoomCellData.Floor;
                                }
                            }
                        }
                    }
                }
                break;

            case Side.Bottom:
                for (int y = 0; y < offset + 1; y++)
                {
                    for (int x = offset; x < maximumSize - offset; x++)
                    {
                        if (_roomCells[x, y] == RoomCellData.None)
                        {
                            if (y == offset)
                            {
                                if (x > centerPoint - connectionOffset && x < centerPoint + connectionOffset)
                                {
                                    _roomCells[x, y] = RoomCellData.Floor;
                                }
                                else
                                {
                                    _roomCells[x, y] = RoomCellData.Wall;
                                }
                            }
                            else
                            {
                                if (x == centerPoint - connectionOffset || x == centerPoint + connectionOffset)
                                {
                                    _roomCells[x, y] = RoomCellData.Wall;
                                }
                                else if (x > centerPoint - connectionOffset && x < centerPoint + connectionOffset)
                                {
                                    _roomCells[x, y] = RoomCellData.Floor;
                                }
                            }
                        }
                    }
                }
                break;

            case Side.Left:
                for (int x = 0; x < offset + 1; x++)
                {
                    for (int y = offset; y < maximumSize - offset; y++)
                    {
                        if (_roomCells[x, y] == RoomCellData.None)
                        {
                            if (x == offset)
                            {
                                if (y > centerPoint - connectionOffset && y < centerPoint + connectionOffset)
                                {
                                    _roomCells[x, y] = RoomCellData.Floor;
                                }
                                else
                                {
                                    _roomCells[x, y] = RoomCellData.Wall;
                                }
                            }
                            else
                            {
                                if (y == centerPoint - connectionOffset || y == centerPoint + connectionOffset)
                                {
                                    _roomCells[x, y] = RoomCellData.Wall;
                                }
                                else if (y > centerPoint - connectionOffset && y < centerPoint + connectionOffset)
                                {
                                    _roomCells[x, y] = RoomCellData.Floor;
                                }
                            }
                        }
                    }
                }
                break;

            case Side.Right:
                for (int x = maximumSize - offset - 1; x < maximumSize; x++)
                {
                    for (int y = offset; y < maximumSize - offset; y++)
                    {
                        if (_roomCells[x, y] == RoomCellData.None)
                        {
                            if (x == maximumSize - offset - 1)
                            {
                                if (y > centerPoint - connectionOffset && y < centerPoint + connectionOffset)
                                {
                                    _roomCells[x, y] = RoomCellData.Floor;
                                }
                                else
                                {
                                    _roomCells[x, y] = RoomCellData.Wall;
                                }
                            }
                            else
                            {
                                if (y == centerPoint - connectionOffset || y == centerPoint + connectionOffset)
                                {
                                    _roomCells[x, y] = RoomCellData.Wall;
                                }
                                else if (y > centerPoint - connectionOffset && y < centerPoint + connectionOffset)
                                {
                                    _roomCells[x, y] = RoomCellData.Floor;
                                }
                            }
                        }
                    }
                }
                break;

            default:
                break;
            }
        }