Exemplo n.º 1
0
	// This is an overload of the SetupRoom function and has a corridor parameter that represents the corridor entering the room.
	public void SetupRoom (IntRange widthRange, IntRange heightRange, int columns, int rows, Corridor corridor, bool hasKey)
	{
		this.hasKey = hasKey;

		// Set the entering corridor direction.
		enteringCorridor = corridor.direction;

		// Set random values for width and height.
		roomWidth = widthRange.Random;
		roomHeight = heightRange.Random;

		//set the location that the key will spawn in in the room.
		keyLocation.x = widthRange.Random;
		keyLocation.y = heightRange.Random;


		switch (corridor.direction)
		{
		// If the corridor entering this room is going north...
		case Direction.North:
			// ... the height of the room mustn't go beyond the board so it must be clamped based
			// on the height of the board (rows) and the end of corridor that leads to the room.
			roomHeight = Mathf.Clamp(roomHeight, 1, rows - corridor.EndPositionY);

			// The y coordinate of the room must be at the end of the corridor (since the corridor leads to the bottom of the room).
			yPos = corridor.EndPositionY;

			// The x coordinate can be random but the left-most possibility is no further than the width
			// and the right-most possibility is that the end of the corridor is at the position of the room.
			xPos = Random.Range (corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX);

			// This must be clamped to ensure that the room doesn't go off the board.
			xPos = Mathf.Clamp (xPos, 0, columns - roomWidth);
			break;
		case Direction.East:
			roomWidth = Mathf.Clamp(roomWidth, 1, columns - corridor.EndPositionX);
			xPos = corridor.EndPositionX;

			yPos = Random.Range (corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY);
			yPos = Mathf.Clamp (yPos, 0, rows - roomHeight);
			break;
		case Direction.South:
			roomHeight = Mathf.Clamp (roomHeight, 1, corridor.EndPositionY);
			yPos = corridor.EndPositionY - roomHeight + 1;

			xPos = Random.Range (corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX);
			xPos = Mathf.Clamp (xPos, 0, columns - roomWidth);
			break;
		case Direction.West:
			roomWidth = Mathf.Clamp (roomWidth, 1, corridor.EndPositionX);
			xPos = corridor.EndPositionX - roomWidth + 1;

			yPos = Random.Range (corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY);
			yPos = Mathf.Clamp (yPos, 0, rows - roomHeight);
			break;
		}
	}
Exemplo n.º 2
0
 public void addCorridor(Corridor corr)
 {
     if (_roomsAndCorridors.Count != 0)
     {
         Room room = (Room)_roomsAndCorridors[_roomsAndCorridors.Count - 1];
         room.setCorridorOutcoming(corr);
         corr.setSourceRoom(room);
     }
     _roomsAndCorridors.Add(corr);
 }
Exemplo n.º 3
0
        public void walkableCell_verticalCorridor()
        {
            Corridor corr = new Corridor(new Cell(0, 0), new Grid(3, 4), Corridor.Orientation.vertical);

            Cell[] result   = corr.walkableCells(false);
            Cell[] expected = new Cell[6] {
                new Cell(0, 1), new Cell(0, 2), new Cell(1, 1), new Cell(1, 2), new Cell(2, 1), new Cell(2, 2)
            };
            Assert.IsTrue(XTestUtils.areEquals(expected, result));
        }
Exemplo n.º 4
0
 public void addRoom(Room aRoom)
 {
     if (_roomsAndCorridors.Count != 0)
     {
         Corridor corr = (Corridor)_roomsAndCorridors[_roomsAndCorridors.Count - 1];
         corr.setDestinationRoom(aRoom);
         aRoom.setCorridorIncoming(corr);
     }
     _roomsAndCorridors.Add(aRoom);
 }
Exemplo n.º 5
0
    //private void ClearCollections()
    //{
    //    roomsToSlice.Clear();
    //    leafNodes.Clear();
    //    allNodes.Clear();
    //    borders.Clear();
    //}

    //连接相邻房间
    private void ConnectNeighborRooms(RoomNode left, RoomNode right, PartitionLine passage, int corridorWidth, int minRoomWidth, int minRoomHeight, int lineWidth)
    {
        Direction         direction = passage.direction;
        List <Vector2Int> temp      = new List <Vector2Int>();

        if (direction == Direction.Horizontal)
        {
            int x;
            if (left.Width < 2 * minRoomWidth + 2 * lineWidth - 1)
            {
                x = seed.Next(left.bottomLeft.x + 1 + corridorWidth, right.topRight.x - corridorWidth);
            }
            else
            {
                x = (seed.Next(0, 2) == 0) ? seed.Next(left.bottomLeft.x + corridorWidth, left.bottomLeft.x + minRoomWidth - corridorWidth) : seed.Next(right.topRight.x - minRoomWidth + corridorWidth + 2, right.topRight.x - corridorWidth);
            }
            for (int y = right.topRight.y + 1; y < left.bottomLeft.y; y++)
            {
                for (int xOffset = x - corridorWidth; xOffset <= x + corridorWidth; xOffset++)
                {
                    temp.Add(new Vector2Int(xOffset, y));
                }
            }
            //gates.Add(new Vector2Int(x, left.bottomLeft.y));
            //gates.Add(new Vector2Int(x, right.topRight.y));
        }
        else if (direction == Direction.Vertical)
        {
            int y;
            if (left.Height < 2 * minRoomHeight + 2 * lineWidth - 1)
            {
                y = seed.Next(left.bottomLeft.y + 1 + corridorWidth, right.topRight.y - corridorWidth);
            }
            else
            {
                y = (seed.Next(0, 2) == 0) ? seed.Next(left.bottomLeft.y + 1 + corridorWidth, left.bottomLeft.y + minRoomHeight - corridorWidth) : seed.Next(right.topRight.y - minRoomHeight + corridorWidth + 1, right.topRight.y - corridorWidth);
            }
            for (int x = left.topRight.x + 1; x < right.bottomLeft.x; x++)
            {
                for (int yOffset = y - corridorWidth; yOffset <= y + corridorWidth; yOffset++)
                {
                    temp.Add(new Vector2Int(x, yOffset));
                }
            }
            //gates.Add(new Vector2Int(left.topRight.x, y));
            //gates.Add(new Vector2Int(right.bottomLeft.x, y));
        }
        gates.Add(temp[0]);
        gates.Add(temp[temp.Count - 1]);
        //temp.RemoveAt(0);
        //temp.RemoveAt(temp.Count - 1);
        Corridor corridor = new Corridor(temp, (direction == Direction.Horizontal)?Direction.Vertical:Direction.Horizontal);

        corridors.Add(corridor);
    }
Exemplo n.º 6
0
    private void MinimumSpanningTree()
    {
        List <Room> connectedRooms = new List <Room>();

        corridors = new List <Corridor>();

        connectedRooms.Add(rooms[0]);

        while (connectedRooms.Count < rooms.Count)
        {
            var             minLength  = new KeyValuePair <Room, Corridor>();
            List <Corridor> deleteList = new List <Corridor>();

            foreach (Room room in connectedRooms)
            {
                foreach (var pair in room.RoomCorridor)
                {
                    if (connectedRooms.Contains(pair.Key))
                    {
                        continue;
                    }
                    if (minLength.Value == null || minLength.Value.length > pair.Value.length)
                    {
                        minLength = pair;
                    }
                }
            }

            foreach (var pair in minLength.Key.RoomCorridor)
            {
                if (connectedRooms.Contains(pair.Key) && minLength.Value != pair.Value)
                {
                    deleteList.Add(pair.Value);
                }
            }

            for (int i = deleteList.Count - 1; i >= 0; i--)
            {
                Corridor corridor = deleteList[i];
                corridor.connectedRooms[0].RoomCorridor.Remove(corridor.connectedRooms[1]);
                corridor.connectedRooms[1].RoomCorridor.Remove(corridor.connectedRooms[0]);
                deleteList.RemoveAt(i);
            }

            if (!connectedRooms.Contains(minLength.Key))
            {
                connectedRooms.Add(minLength.Key);
            }
            if (!corridors.Contains(minLength.Value))
            {
                corridors.Add(minLength.Value);
            }
        }
    }
Exemplo n.º 7
0
    public void GenerateEntrance()
    {
        int objQuadrantInt = QuadrantCalc.Quadrant.WithinWhichQuadrant(QuadrantCalculator.physObject);
        var sidePoints     = Corridor.CalculateSide();

        Corridor.CreateCorridorBetween(sidePoints.Item1, sidePoints.Item2, corrPrefab, Corridor.corridorType.SIDE);

        Corridor.CreateCorridorBetween(Corridor.lastPosVector, GetQuadrantBasedPosition(objQuadrantInt), corrPrefab, Corridor.corridorType.ENTRANCE);
        entrancePosition = objQuadrantInt;
        Corridor.ChangeActiveAllOfType(Corridor.corridorType.EXIT);
    }
Exemplo n.º 8
0
    private void Start()
    {
        for (int i = 0; i < corridorsToGenerate; i++)
        {
            Corridor corridor = GetComponent <Corridor>();
            corridor.GenerateCorridor();

            SpawnRoom(corridor.squareList[0].transform.position);
            SpawnRoom(corridor.squareList[corridor.squareList.Count - 1].transform.position);
        }
    }
    void CreateRoomsAndCorridors()
    {
        // Create the rooms array with a random size.
        rooms = new Room[numRooms.Random];

        // There should be one less corridor than there is rooms.
        corridors = new Corridor[rooms.Length - 1];

        // Create the first room and corridor.
        rooms[0]     = new Room();
        corridors[0] = new Corridor();

        // Setup the first room, there is no previous corridor so we do not use one.
        rooms[0].SetupRoom(roomWidth, roomHeight, columns, rows);

        // Setup the first corridor using the first room.
        corridors[0].SetupCorridor(rooms[0], corridorLength, roomWidth, roomHeight, columns, rows, true);

        for (int i = 1; i < rooms.Length; i++)
        {
            Debug.Log("Room " + i + " created");
            // Create a room.
            rooms[i] = new Room();

            // Setup the room based on the previous corridor.
            rooms[i].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[i - 1]);

            // If we haven't reached the end of the corridors array...
            if (i < corridors.Length)
            {
                Debug.Log("Corridor " + i + " created");
                // ... create a corridor.
                corridors[i] = new Corridor();

                // Setup the corridor based on the room that was just created.
                corridors[i].SetupCorridor(rooms[i], corridorLength, roomWidth, roomHeight, columns, rows, false);
            }

            // When halfway through the room creation, place player prefab
            if (i == 2)
            {
                Debug.Log("Player instantiated");
                Vector3 playerPos = new Vector3(rooms[i].xPos, rooms[i].yPos, 0);
                Instantiate(player, playerPos, Quaternion.identity);
            }

            if (i == 4)
            {
                Debug.Log("Exit Tile instantiated");
                Vector3 exitPos = new Vector3(rooms[i].xPos, rooms[i].yPos, 0);
                Instantiate(exit, exitPos, Quaternion.identity);
            }
        }
    }
Exemplo n.º 10
0
    void CreateRoomsAndCorridors()
    {
        // Get Div and Mod of hit_power to adjust amount of traps

        // mod_power adjusts the exponential amount of traps
        mod_power = trap_difficulty % 10;

        // div_power adjusts the starting amount of traps. Caps at 20.
        div_power = trap_difficulty / 10;
        if (div_power > 20)
        {
            div_power = 20;
        }

        // Function creates odds of getting a trap. Maths by me. :D
        //At hit_power 20, mod_power 9, There is a 95.14% chance of getting a trap.
        trap_chance = Mathf.Pow(mod_power, (0.04f * mod_power) + 1.0f) + Mathf.Pow(div_power, (0.02f * div_power) + 1.0f) + 9.0f;


        // Create the rooms array with a random size.
        rooms = new Room[numRooms.Random];

        // There should be one less corridor than there is rooms.
        corridors = new Corridor[rooms.Length - 1];

        // Create the first room and corridor.
        rooms[0]     = new Room();
        corridors[0] = new Corridor();

        // Setup the first room, there is no previous corridor so we do not use one.
        rooms[0].SetupRoom(roomWidth, roomHeight, columns, rows);

        // Setup the first corridor using the first room.
        corridors[0].SetupCorridor(rooms[0], corridorLength, roomWidth, roomHeight, columns, rows, true);

        for (int i = 1; i < rooms.Length; i++)
        {
            // Create a room.
            rooms[i] = new Room();

            // Setup the room based on the previous corridor.
            rooms[i].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[i - 1], reward_chance, people_chance);

            // If we haven't reached the end of the corridors array...
            if (i < corridors.Length)
            {
                // ... create a corridor.
                corridors[i] = new Corridor();

                // Setup the corridor based on the room that was just created.
                corridors[i].SetupCorridor(rooms[i], corridorLength, roomWidth, roomHeight, columns, rows, false);
            }
        }
    }
Exemplo n.º 11
0
    public void replaceOtherCorridor(Corridor other)
    {
        int     newCorridoorType = 0;
        Vector3 targetPos        = other.transform.position;

        Destroy(other.gameObject);
        //get new corridor using a fn or sth taking argument "corridorType"
        GameObject newCorridor = null;

        Instantiate(newCorridor, targetPos, Quaternion.identity);
    }
Exemplo n.º 12
0
        public void fitting_case2()
        {
            Board    board = new Board(new Grid(100, 100));
            Corridor corr  = new Corridor(new Cell(75, 61), new Grid(3, 6), Corridor.Orientation.horizontal);

            board.addCorridor(corr);

            Room room = new Room(new Cell(70, 66), new Grid(15, 6));

            Assert.IsTrue(board.fitsIn(room));
        }
Exemplo n.º 13
0
 void initArrays(Corridor toInit)
 {
     //  Debug.Log(this.name+" initArrays");
     toInit.m_children = new Corridor[toInit.m_nbExit];
     toInit.m_triggers = new TriggerCorridor[toInit.m_nbExit];
     for (int i = 0; i < m_nbExit; i++)
     {
         toInit.m_children[i] = null;
     }
     toInit.m_triggers = this.GetComponentsInChildren <TriggerCorridor>();
 }
    private Corridor GenerateCorridor(Room room_a, Room room_b)
    {
        Corridor corridor  = new Corridor();
        string   direction = "";

        // finding the direction from room A to B
        if (room_a.id == room_b.id)
        {
            while (direction == "")
            {
                direction = string.Concat(" NS"[Random.Range(0, 3)], " WE"[Random.Range(0, 3)]).Trim();
            }
        }
        else
        {
            if (room_a.y != room_b.y)
            {
                direction += room_a.y > room_b.y ? 'N' : 'S';
            }
            if (room_a.x != room_b.x)
            {
                direction += room_a.x > room_b.x ? 'W' : 'E';
            }
        }
        //randomizing doors
        corridor.door1 = Random.Range(0, 2) > 0;
        corridor.door2 = Random.Range(0, 2) > 0;

        // creating door-points (on the edge of the rooms)
        RoomEntrance dp;

        dp          = GetDoorPoint(room_a, direction);
        corridor.P1 = dp.point;
        Point start_p = GetNextPoint(dp);

        dp          = GetDoorPoint(room_b, direction, true);
        corridor.P2 = dp.point;
        Point dest_p = GetNextPoint(dp);

        // generating path
        List <Point> path = CalculatePath(start_p, dest_p);

        if (path.Count > 0)
        {
            corridor.points = path;
            corridor.rooms  = new int[] { room_a.id, room_b.id };
            corridor.id     = corridors.Count;
            return(corridor);
        }
        else
        {
            return(null);
        }
    }
Exemplo n.º 15
0
    void CreateRoomsAndCorridors()
    {
        // Create the rooms array with a random size.
        rooms = new Room[numRooms.Random];

        // There should be one less corridor than there is rooms.
        corridors = new Corridor[rooms.Length - 1];

        // Create the first room and corridor.
        rooms[0]     = new Room();
        corridors[0] = new Corridor();

        // Setup the first room, there is no previous corridor so we do not use one.
        rooms[0].SetupRoom(roomWidth, roomHeight, columns, rows);

        // Setup the first corridor using the first room.
        corridors[0].SetupCorridor(rooms[0], corridorLength, roomWidth, roomHeight, columns, rows, true);

        for (int i = 1; i < rooms.Length; i++)
        {
            // Create a room.
            rooms[i] = new Room();

            // Setup the room based on the previous corridor.
            rooms[i].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[i - 1]);

            // If we haven't reached the end of the corridors array...
            if (i < corridors.Length)
            {
                // ... create a corridor.
                corridors[i] = new Corridor();

                // Setup the corridor based on the room that was just created.
                corridors[i].SetupCorridor(rooms[i], corridorLength, roomWidth, roomHeight, columns, rows, false);
            }

            if (i == Mathf.Ceil(rooms.Length * .5f))
            {
                Vector3 playerPos = new Vector3(rooms[i].xPos, rooms[i].yPos, 0);
                checkPlayerValue = playerPos;
                Instantiate(playerFloor, playerPos, Quaternion.identity);
                Instantiate(player, playerPos, Quaternion.identity);
            }
            if (i == rooms.Length - 1)
            {
                Vector3 exitPos = new Vector3(rooms[i].xPos + Mathf.Floor((Random.value * rooms[i].roomWidth)
                                                                          % (rooms[i].roomWidth - 1)), rooms[i].yPos + Mathf.Floor((Random.value * rooms[i].roomHeight)
                                                                                                                                   % (rooms[i].roomHeight - 1)), 0);
                checkExitValue = exitPos;
                Instantiate(playerFloor, exitPos, Quaternion.identity);
                Instantiate(exit, exitPos, Quaternion.identity);
            }
        }
    }
Exemplo n.º 16
0
    Corridor DigCorridorUpTo(Room fromRoom, Room goalRoom)
    {
        var startPoint = new Point(Random.Range(fromRoom.GlobalPos.X + 1, fromRoom.GlobalPos.X + fromRoom.Width - 1),
                                   fromRoom.GlobalPos.Y + fromRoom.Height - 1);
        var   corridor = new Corridor(startPoint);
        Point goal     = goalRoom.GetRandomPointInsideRoom(2);

        corridor.Points.Add(new Point(startPoint.X, goal.Y));
        corridor.Points.Add(new Point(goal.X, goal.Y));
        return(corridor);
    }
Exemplo n.º 17
0
    public void BuildFixedRoom(int width, int height, int columns, int rows, Corridor corridor)
    {
        // Set the entering corridor direction.
        enteringCorridor = corridor.direction;

        //Set value for height and width
        roomWidth  = width;
        roomHeight = height;
        FloorType  = TileType.Floor;

        switch (corridor.direction)
        {
        // If the corridor entering this room is going north...
        case Direction.North:
            // ... the height of the room mustn't go beyond the board so it must be clamped based
            // on the height of the board (rows) and the end of corridor that leads to the room.
            roomHeight = Mathf.Clamp(roomHeight, 1, rows - corridor.EndPositionY);

            // The y coordinate of the room must be at the end of the corridor (since the corridor leads to the bottom of the room).
            yPos = corridor.EndPositionY;

            // The x coordinate can be random but the left-most possibility is no further than the width
            // and the right-most possibility is that the end of the corridor is at the position of the room.
            xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX);

            // This must be clamped to ensure that the room doesn't go off the board.
            xPos = Mathf.Clamp(xPos, 0, columns - roomWidth);
            break;

        case Direction.East:
            roomWidth = Mathf.Clamp(roomWidth, 1, columns - corridor.EndPositionX);
            xPos      = corridor.EndPositionX;

            yPos = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY);
            yPos = Mathf.Clamp(yPos, 0, rows - roomHeight);
            break;

        case Direction.South:
            roomHeight = Mathf.Clamp(roomHeight, 1, corridor.EndPositionY);
            yPos       = corridor.EndPositionY - roomHeight + 1;

            xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX);
            xPos = Mathf.Clamp(xPos, 0, columns - roomWidth);
            break;

        case Direction.West:
            roomWidth = Mathf.Clamp(roomWidth, 1, corridor.EndPositionX);
            xPos      = corridor.EndPositionX - roomWidth + 1;

            yPos = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY);
            yPos = Mathf.Clamp(yPos, 0, rows - roomHeight);
            break;
        }
    }
Exemplo n.º 18
0
        private void ModifyCorridor(Corridor corridor)
        {
            var lightY = corridor.TopRightCorner.Y - 1;

            for (var lightX = corridor.BottomLeftCorner.X; lightX <= corridor.TopRightCorner.X; lightX++)
            {
                if (lightX % 8 == 0)
                {
                    corridor.AddFeature(new IntVector2(lightX, lightY), FeatureTypes.WallLight);
                }
            }
        }
Exemplo n.º 19
0
    void instantiateChildren(Corridor previous)
    {
        m_children[0] = previous;

        for (int i = 0; i < m_nbExit; i++)
        {
            if (m_children[i] == null && m_exitPositions[i].GetComponent <TriggerCorridor>().m_planeRend.enabled == false /*.GetComponentInChildren<MeshRenderer>().enabled == false*/)
            {
                m_children[i] = setPoolObjActive(ObjectPool.instance.GetObjectForType(randomObjName(this), false).GetComponent <Corridor>(), this, i /*, false*/);
            }
        }
    }
Exemplo n.º 20
0
 public void openExits(Corridor toOpen)
 {
     //Debug.Log("toOpen ID : " + toOpen.instanceID);
     for (int i = 0; i < toOpen.m_nbExit; i++) //(Corridor _child in temp_parent.m_children)
     {
         if (toOpen.m_exitPositions[i] != null)
         {
             toOpen.m_exitPositions[i].GetComponent <TriggerCorridor>().m_planeCol.enabled  = false /*.GetComponentInChildren<MeshCollider>().enabled = false*/;
             toOpen.m_exitPositions[i].GetComponent <TriggerCorridor>().m_planeRend.enabled = false /*.GetComponentInChildren<MeshRenderer>().enabled = false*/;
         }
     }
 }
Exemplo n.º 21
0
    // This is an overload of the SetupRoom function and has a corridor parameter that represents the corridor entering the room.
    public void SetupRoom(GenerationParams gParams, Corridor corridor)
    {
        // Set the entering corridor direction.
        enteringCorridor = corridor.direction;

        // Set random values for width and height.
        roomWidth  = gParams.roomWidth.Random;
        roomHeight = gParams.roomHeight.Random;

        switch (corridor.direction)
        {
        // If the corridor entering this room is going north...
        case Direction.North:
            // ... the height of the room mustn't go beyond the board so it must be clamped based
            // on the height of the board (rows) and the end of corridor that leads to the room.
            roomHeight = Mathf.Clamp(roomHeight, 1, gParams.rows - corridor.EndPositionY);

            // The y coordinate of the room must be at the end of the corridor (since the corridor leads to the bottom of the room).
            yPos = corridor.EndPositionY;

            // The x coordinate can be random but the left-most possibility is no further than the width
            // and the right-most possibility is that the end of the corridor is at the position of the room.
            xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX);

            // This must be clamped to ensure that the room doesn't go off the board.
            xPos = Mathf.Clamp(xPos, 0, gParams.columns - roomWidth);
            break;

        case Direction.East:
            roomWidth = Mathf.Clamp(roomWidth, 1, gParams.columns - corridor.EndPositionX);
            xPos      = corridor.EndPositionX;

            yPos = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY);
            yPos = Mathf.Clamp(yPos, 0, gParams.rows - roomHeight);
            break;

        case Direction.South:
            roomHeight = Mathf.Clamp(roomHeight, 1, corridor.EndPositionY);
            yPos       = corridor.EndPositionY - roomHeight + 1;

            xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX);
            xPos = Mathf.Clamp(xPos, 0, gParams.columns - roomWidth);
            break;

        case Direction.West:
            roomWidth = Mathf.Clamp(roomWidth, 1, corridor.EndPositionX);
            xPos      = corridor.EndPositionX - roomWidth + 1;

            yPos = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY);
            yPos = Mathf.Clamp(yPos, 0, gParams.rows - roomHeight);
            break;
        }
    }
Exemplo n.º 22
0
    private void SetMapBytes(Corridor ri)
    {
        for (int y = ri.Y1; y <= ri.Y2; y++)
        {
            for (int x = ri.X1; x <= ri.X2; x++)
            {
                this.map[x][y] = (byte)TileType.Empty;
            }
        }

        if (ri.Direction == Direction.North || ri.Direction == Direction.South)
        {
            for (int y = ri.Y1; y <= ri.Y2; y++)
            {
                if (this.map[ri.X1 - 1][y] == (byte)TileType.None)
                {
                    this.map[ri.X1 - 1][y] = (byte)TileType.Wall;
                }

                if (this.map[ri.X2 + 1][y] == (byte)TileType.None)
                {
                    this.map[ri.X2 + 1][y] = (byte)TileType.Wall;
                }
            }

            this.map[ri.X1][ri.Y1] = (byte)TileType.DoorEW;
            this.map[ri.X1][ri.Y2] = (byte)TileType.DoorEW;

            this.map[ri.X1 + 1][ri.Y1] = (byte)TileType.DoorEW;
            this.map[ri.X1 + 1][ri.Y2] = (byte)TileType.DoorEW;
        }
        else
        {
            for (int x = ri.X1; x <= ri.X2; x++)
            {
                if (this.map[x][ri.Y1 - 1] == (byte)TileType.None)
                {
                    this.map[x][ri.Y1 - 1] = (byte)TileType.Wall;
                }

                if (this.map[x][ri.Y2 + 1] == (byte)TileType.None)
                {
                    this.map[x][ri.Y2 + 1] = (byte)TileType.Wall;
                }
            }

            this.map[ri.X1][ri.Y1] = (byte)TileType.DoorNS;
            this.map[ri.X2][ri.Y1] = (byte)TileType.DoorNS;

            this.map[ri.X1][ri.Y1 + 1] = (byte)TileType.DoorNS;
            this.map[ri.X2][ri.Y1 + 1] = (byte)TileType.DoorNS;
        }
    }
Exemplo n.º 23
0
        public static void CreateCorridorBetween(Vector3 start, Vector3 end, typeOfCorridor type, bool standardCorridor = true) // Instantiates the prefab of a specific size to work as a corridor.
        {
            Corridor   tempCorr   = new Corridor(start, end, type, standardCorridor);
            GameObject tempObject = Instantiate(_floorPrefab, new Vector3(0, 0, 0), Quaternion.identity);

            tempObject.transform.parent        = CorridorContainer.transform;
            tempObject.transform.localScale    = tempCorr.size;
            tempObject.transform.localPosition = tempCorr.center;
            tempCorr.floorObject = tempObject;
            tempCorr.SetFloorMaterial();
            listOfPoints.Add(tempCorr.end);
        }
Exemplo n.º 24
0
        public void DefaultContructor_EmptyObject_EmptyProperties()
        {
            //Arrange
            var sut = new Corridor();

            //Act
            var(start, end) = sut.Vector;

            //Assert
            Assert.Equal((0, 0), (start.X, start.Y));
            Assert.Equal((0, 0), (end.X, end.Y));
        }
Exemplo n.º 25
0
        public void ParameterizedConstructor_ValidValues_ValidProperties()
        {
            //Arrange
            var sut = new Corridor(new Vector(new Tile(1, 2), new Tile(3, 4)));

            //Act
            var(start, end) = sut.Vector;

            //Assert
            Assert.Equal((1, 2), (start.X, start.Y));
            Assert.Equal((3, 4), (end.X, end.Y));
        }
Exemplo n.º 26
0
    protected void GenerateRemainingRooms(Board board)
    {
        int failedRoomAttempts = 0;
        int roomsToGenerate    = numRooms.Random;

        InitRngIdentifiers(roomsToGenerate);

        //Make and shuffle room ids

        for (int i = 1; i < roomsToGenerate; i++)
        {
            if (failedRoomAttempts >= failedRoomsAllowed)
            {
                Debug.Log("Failed room total reached");
                break;
            }
            Room stemRoom = SelectStemRoom();
            if (stemRoom.CanMakeMoreDoors())
            {
                Doorway possibleDoorway = stemRoom.PossibleDoorway();

                Corridor corridorAttempt = new Corridor();
                corridorAttempt.SetupCorridor(possibleDoorway, board, 0, identifier);

                Room roomAttempt = RandomRoom();
                roomAttempt.SetupRoom(corridorAttempt.door2, identifier);

                bool valid = roomAttempt.TestRoomValidity(board);

                //Do testing
                if (valid)
                {
                    roomAttempt.PostValiditySetup();
                    corridorAttempt.door2.room = roomAttempt;
                    stemRoom.doorways.Add(possibleDoorway);
                    corridors.Add(corridorAttempt);
                    rooms.Add(roomAttempt);
                    roomRngIdentifiers.RemoveAt(0);
                }
                else
                {
                    i--;
                    failedRoomAttempts++;
                }
            }
            else
            {
                i--;
                failedRoomAttempts++;
            }
        }
    }
Exemplo n.º 27
0
        public CaveBoard asBoard()
        {
            checkConstraints();

            Board board = _dunGen.asBoard();
            ShapeCellularAutomaton     roomAlgo    = new ShapeCellularAutomaton(_seed, _cellularFillChance, _cellularSmoothingStep);
            CustomSeededPickerStrategy shapePicker = new CustomSeededPickerStrategy(_seed);

            CaveBoard      result    = new CaveBoard(board.rows(), board.cols());
            List <IXShape> onlyRooms = new List <IXShape>();

            _logger.info("Rooms: " + board.rooms().Length);
            foreach (Room each in board.rooms())
            {
                Cell       leftVert = each.topLeftVertex();
                int        rows     = each.height();
                int        cols     = each.width();
                APolyShape currentRoom; //Select a shape for the Room
                if (shapePicker.drawBetween(0, 100) < 50)
                {
                    currentRoom = new RectShape(leftVert, new OIGrid(rows, cols));
                }
                else
                {
                    currentRoom = new ElliShape(leftVert, new OIGrid(rows, cols));
                }
                _logger.info("Shape type: " + currentRoom.GetType());
                roomAlgo.applyOn(currentRoom);

                _logger.info("Shape regions before clean: " + currentRoom.regionsNumber());
                if (!currentRoom.hasRegions())
                {
                    _logger.warning("No Region found. Room will be skipped!!!");
                    continue;
                }
                currentRoom.deleteRegionsButTheBiggest();
                _logger.info("Shape regions after clean: " + currentRoom.regionsNumber());


                onlyRooms.Add(currentRoom);
                if (onlyRooms.Count > 1)
                {
                    IXShape  previousRoom    = onlyRooms[onlyRooms.Count - 2];
                    int      corrIndex       = onlyRooms.Count - 2;
                    Corridor corr            = board.corridors()[corrIndex];
                    int      corridorSection = corr.isVertical() ? corr.width() : corr.height();
                    result.addCorridor(CaveCorridorFactory.createCorrShape(previousRoom, currentRoom, corridorSection));
                }
                result.addRoom(currentRoom);
            }
            return(result);
        }
Exemplo n.º 28
0
    void CreateRoomsAndCorridors()
    {
        // Create the rooms array with a random size.
        rooms = new Room[numRooms.Random];

        // There should be one less corridor than there is rooms.
        corridors = new Corridor[rooms.Length - 1];

        // Create the first room and corridor.
        rooms[0]     = new Room();
        corridors[0] = new Corridor();

        // Setup the first room, there is no previous corridor so we do not use one.
        rooms[0].SetupRoom(roomWidth, roomHeight, columns, rows);

        // Setup the first corridor using the first room.
        corridors[0].SetupCorridor(rooms[0], corridorLength, roomWidth, roomHeight, columns, rows, true);

        for (int i = 1; i < rooms.Length; i++)
        {
            // Create a room.
            rooms[i] = new Room();

            // Setup the room based on the previous corridor.
            rooms[i].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[i - 1]);

            // If we haven't reached the end of the corridors array...
            if (i < corridors.Length)
            {
                // ... create a corridor.
                corridors[i] = new Corridor();

                // Setup the corridor based on the room that was just created.
                corridors[i].SetupCorridor(rooms[i], corridorLength, roomWidth, roomHeight, columns, rows, false);
            }

            if (playerCreated == false)
            {
                Vector3 playerPos = new Vector3(rooms[i].xPos, rooms[i].yPos, 0);
                Instantiate(player, playerPos * scale, Quaternion.identity);
                print("created player");
                playerCreated = true;
            }
            if (exitCreated == false)
            {
                Vector3    exitPos   = new Vector3(rooms[0].xPos, rooms[0].yPos, 0);
                GameObject levelExit = Instantiate(exit, exitPos * scale, Quaternion.identity);
                levelExit.name = "Exit";
                exitCreated    = true;
            }
        }
    }
Exemplo n.º 29
0
        // metoda za definiranje tocaka konstrukcije
        // Vraca structure Point3d koji se primjenjuje
        // za izradu ostalih objecata classe: alignment, profile i corridor

        // metoda za odabir pravilnog corridora
        // želimo je ostaviti private tako da se ograniči pristup
        // krucijalno je imati pravilan corridor za funkcioniranje aplikacije
        // moguća danja nadogradnja da traži subassembly sa određenim imenom
        // potrebna danja rasprava

        private Corridor PlovniPutMetoda()
        {
            foreach (ObjectId objId in civDoc.CorridorCollection)
            {
                Corridor corr = objId.GetObject(OpenMode.ForRead) as Corridor;
                if (corr.Name == "PlovniPut")
                {
                    return(corr);
                }
            }

            return(null);
        }
Exemplo n.º 30
0
        public void walkableCell_roomWithSouthIncomingCorridor()
        {
            Room     room = new Room(new Cell(0, 0), new Grid(3, 3));
            Corridor corr = new Corridor(new Cell(2, 0), new Grid(3, 3), Corridor.Orientation.vertical);

            room.setCorridorIncoming(corr);

            Cell[] result   = room.walkableCells(false);
            Cell[] expected = new Cell[1] {
                new Cell(1, 1)
            };
            Assert.IsTrue(XTestUtils.areEquals(expected, result));
        }
Exemplo n.º 31
0
        public void walkableCell_oneRoom5x3withOneEastOutcomingCorridor3x3()
        {
            Room     room = new Room(new Cell(0, 0), new Grid(5, 3));
            Corridor corr = new Corridor(new Cell(1, 2), new Grid(3, 3), Corridor.Orientation.horizontal);

            room.setCorridorOutcoming(corr);

            Cell[] result   = room.walkableCells(false);
            Cell[] expected = new Cell[3] {
                new Cell(1, 1), new Cell(2, 1), new Cell(3, 1)
            };
            Assert.IsTrue(XTestUtils.areEquals(expected, result));
        }
Exemplo n.º 32
0
    void CreateRoomsAndCorridors()
    {
        rooms = new Room[numRooms.Random]; //setup the rooms array;

        corridors = new Corridor[rooms.Length - 1]; // one less corridor than the rooms so that we didn't finish on a corridor;

        rooms[0] = new Room();
        corridors[0] = new Corridor(); //first room and first corridor

        //setUp first room
        rooms[0].SetUpRoom(roomWidth, roomHeight, columns, rows);

        //setUp the first corridor using the first room
        corridors[0].SetUpCorridor(rooms[0], corridorLength, roomWidth, roomHeight, columns, rows, true);

        int RandomRoomIndex = Random.Range(1, rooms.Length);
        int RandomIndexExit = (RandomRoomIndex + 3) % rooms.Length;

        //setUp the other rooms and corridors
        for (int i = 1; i < rooms.Length; i++)
        {
            //create a room
            rooms[i] = new Room();

            //setUp the room based on the previous corridor
            rooms[i].SetUpRoom(roomWidth, roomHeight, columns, rows, corridors[i - 1]);

            if (i < corridors.Length)
            {
                corridors[i] = new Corridor();

                corridors[i].SetUpCorridor(rooms[i], corridorLength, roomWidth, roomHeight, columns, rows, false);
            }

            if (i == RandomRoomIndex) //better computation with  *
            {
                Vector3 playerPos = new Vector3(rooms[i].xPos, rooms[i].yPos, 0);
                Instantiate(player, playerPos, Quaternion.identity);
            }

            if (i == RandomIndexExit)
            {
                IntRange randomPosX = new IntRange(rooms[i].xPos, rooms[i].xPos + rooms[i].roomWidth - 1);
                IntRange randomPosY = new IntRange(rooms[i].yPos, rooms[i].yPos + rooms[i].roomHeight - 1);
                Vector3 ExitPos = new Vector3(randomPosX.Random, randomPosY.Random, 0);
                Instantiate(Exit, ExitPos, Quaternion.identity);
            }

        }
    }
Exemplo n.º 33
0
    public void SetUpRoom(IntRange widthRange, IntRange heightRange, int columns, int rows, Corridor corridor)
    {
        //assign the enteringCorridor direction
        enteringCorridor = corridor.direction;

        //set random values for width and height
        roomWidth = widthRange.Random;
        roomHeight = heightRange.Random;

        switch(corridor.direction)
        {
            case Direction.North:
                roomHeight = Mathf.Clamp(roomHeight, 1, rows - corridor.EndPositionY);
                yPos = corridor.EndPositionY;
                xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX);
                xPos = Mathf.Clamp(xPos, 0, columns - roomWidth);
                break;

            case Direction.East:
                roomWidth = Mathf.Clamp(roomWidth, 1, columns - corridor.EndPositionX);
                xPos = corridor.EndPositionX;
                yPos = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY);
                yPos = Mathf.Clamp(yPos, 0, rows - roomHeight);
                break;

            case Direction.South:
                roomHeight = Mathf.Clamp(roomHeight, 1, corridor.EndPositionY); // come b here to understand otherwise it goes to far
                yPos = corridor.EndPositionY - roomHeight + 1;
                xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX);
                xPos = Mathf.Clamp(xPos, 0, columns - roomWidth);
                break;

            case Direction.West:
                roomWidth = Mathf.Clamp(roomWidth, 1, corridor.EndPositionX); // begin at origin 0 0 0
                xPos = corridor.EndPositionX - roomWidth;
                yPos = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY);
                yPos = Mathf.Clamp(yPos, 0, rows - roomHeight);
                break;
        }
    }
Exemplo n.º 34
0
    public void ConnectEntrances(Entrance entranceA, Entrance entranceB)
    {
        if (entranceA.location == entranceB.location) return;

        CellLocation startLocation;
        if (entranceA.direction == Dir.North) startLocation = entranceA.location.getNorth ();
        else if (entranceA.direction == Dir.South) startLocation = entranceA.location.getSouth ();
        else if (entranceA.direction == Dir.East) startLocation = entranceA.location.getEast ();
        else startLocation = entranceA.location.getWest ();

        CellLocation goalLocation;
        if (entranceB.direction == Dir.North) goalLocation = entranceB.location.getNorth ();
        else if (entranceB.direction == Dir.South) goalLocation = entranceB.location.getSouth ();
        else if (entranceB.direction == Dir.East) goalLocation = entranceB.location.getEast ();
        else goalLocation = entranceB.location.getWest ();

        Corridor corridorStart = new Corridor (startLocation);
        AddCorridor (corridorStart);

        Corridor corridorGoal = new Corridor (goalLocation);
        AddCorridor (corridorGoal);
    }
Exemplo n.º 35
0
    public void newRoom()
    {
        int randomRoom = Random.Range (0, 5);

        switch (randomRoom) {
        case 0:
            // Another corridor
            // Instantiate and generate the corridor
            corridorInstance = Instantiate (corridorPrefab).GetComponent<Corridor> ();
            corridorInstance.Generate ();
            // Put putin in it
            putPutinInRoom (corridorInstance);
            break;
        case 1:
            // Instantiate
            conferenceRoomInstance = Instantiate (conferenceRoomPrefab).GetComponent<ConferenceRoom>();
            // Put putin in it
            putPutinInRoom (conferenceRoomInstance);
            break;
        case 2:
            // Instantiate
            barInstance = Instantiate (barPrefab).GetComponent<Bar> ();
            // Put putin in it
            putPutinInRoom (barInstance);
            break;
        case 3:
            // Instantiate
            bedroomInstance = Instantiate (bedroomPrefab).GetComponent<Bedroom> ();
            // Put putin in it
            putPutinInRoom (bedroomInstance);
            break;
        case 4:
            // Instantiate
            poolInstance = Instantiate (poolPrefab).GetComponent<Pool> ();
            // Put putin in it
            putPutinInRoom (poolInstance);
            break;
        }
    }
    void CreateRoomsAndCorridors()
    {
        // Create the rooms array with a random size.
        rooms = new Room[numRooms.Random];
        // There should be one less corridor than there is rooms.
        corridors = new Corridor[rooms.Length - 1];
        // Create the first room and corridor.
        rooms[0] = new Room();
        corridors[0] = new Corridor();
        // Setup the first room
        rooms[0].SetupRoom(roomWidth, roomHeight, columns, rows);

        // Setup the first corridor using the first room.
        corridors[0].SetupCorridor(rooms[0], corridorLength, roomWidth, roomHeight, columns, rows, true);
        //This puts the player in the lower left corner of the first room
        Vector3 playerPos = new Vector3(rooms[0].xPos, rooms[0].yPos, 0);
        Vector3 goatPos = new Vector3(rooms[0].xPos + 1, rooms[0].yPos + 1, 0);
        Instantiate(player, playerPos, Quaternion.identity);
		Instantiate (goat, goatPos, Quaternion.identity);   

        
        for (int i = 1; i < rooms.Length; i++)
        {
            rooms[i] = new Room();
            rooms[i].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[i - 1]);

            if (i < corridors.Length)
            {
                corridors[i] = new Corridor();
                corridors[i].SetupCorridor(rooms[i], corridorLength, roomWidth, roomHeight, columns, rows, false);
            }
        }
        Vector3 goalPos = new Vector3(rooms[rooms.Length - 1].xPos + 2, rooms[rooms.Length - 1].yPos + 2, 0);
            Instantiate(endGoal, goalPos, Quaternion.identity);
        
    }
Exemplo n.º 37
0
        // Visible for testing
        public Corridor[] GenerateCorridors(int roomCount)
        {
            int corridorCount = roomCount - 1;
            Corridor[] corridors = new Corridor[corridorCount];
            Room lastCreatedRoom = new Room(this.roomsWidth, this.roomsHeight);

            Direction[] excludedDirections = null;
            for (int i = 0; i < corridorCount; ++i)
            {
                Direction[] possibleDirections = Utils.GetAllDirectionsExcluding(excludedDirections);
                Direction direction = RandomProvider.GetRandomElement(possibleDirections);
                Room exitRoom = new Room(this.roomsWidth, this.roomsHeight);
                corridors[i] = new Corridor(this.corridorLength, lastCreatedRoom, exitRoom, direction);
                lastCreatedRoom = exitRoom;

                if (excludedDirections == null)
                {
                    excludedDirections = new Direction[1];
                }
                excludedDirections[0] = Utils.Reverse(direction);
            }

            return corridors;
        }
Exemplo n.º 38
0
    //Overload function to enable other rooms to have corridors
    public void SetupRoom(IntRange widthRange, IntRange heightRange, int columns, int rows, Corridor corridor)
    {
        enteringCorridor = corridor.direction;
        roomWidth = widthRange.Random;
        roomHeight = heightRange.Random;

        switch (corridor.direction)
        {
           
            case Direction.North:
                roomHeight = Mathf.Clamp(roomHeight, 1, rows - corridor.EndPositionY);
                yPos = corridor.EndPositionY;
                xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX);
                //Prevents stuff from going off the map
                xPos = Mathf.Clamp(xPos, 0, columns - roomWidth);
                break;
            case Direction.East:
                roomWidth = Mathf.Clamp(roomWidth, 1, columns - corridor.EndPositionX);
                xPos = corridor.EndPositionX;
                yPos = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY);
                yPos = Mathf.Clamp(yPos, 0, rows - roomHeight);
                break;
            case Direction.South:
                roomHeight = Mathf.Clamp(roomHeight, 1, corridor.EndPositionY);
                yPos = corridor.EndPositionY - roomHeight + 1;
                xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX);
                xPos = Mathf.Clamp(xPos, 0, columns - roomWidth);
                break;
            case Direction.West:
                roomWidth = Mathf.Clamp(roomWidth, 1, corridor.EndPositionX);
                xPos = corridor.EndPositionX - roomWidth + 1;
                yPos = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY);
                yPos = Mathf.Clamp(yPos, 0, rows - roomHeight);
                break;
        }
    }
Exemplo n.º 39
0
	public void SetupDeadEndCorridor(Corridor corridor, IntRange length, IntRange roomWidth, IntRange roomHeight, int columns, int rows, int xStart, int yStart)
	{
		startXPos = xStart;
		startYPos = yStart;

		// Set a random length.
		corridorLength = length.Random;
		// Create a cap for how long the length can be (this will be changed based on the direction and position).
		int maxLength = length.m_Max;

		//Determine which way the dead end corridors goes with respect to the original corridor
		switch(corridor.direction)
		{
		//If non-dead end corridor is generated going north
		case Direction.North:
			//Randomize between North, East, West. Do not want South because that would defeat the purpose of
			//making a dead end corridor
			direction = (Direction)Random.Range (0, 4);
			while(direction == Direction.South)
				direction = (Direction)Random.Range (0, 4);			
			break;
		case Direction.East:
			direction = (Direction)Random.Range (0, 4);
			while(direction == Direction.West)
				direction = (Direction)Random.Range (0, 4);
			break;
		case Direction.South:
			direction = (Direction)Random.Range (0, 4);
			while(direction == Direction.North)
				direction = (Direction)Random.Range (0, 4);
			break;
		case Direction.West:
			direction = (Direction)Random.Range (0, 4);
			while(direction == Direction.East)
				direction = (Direction)Random.Range (0, 4);
			break;
		}

		//Set the values for the dead end corridors to go in their respective directions.
		switch (direction)
		{
		//If dead end corridor is going in the North Direction
		case Direction.North:
			//Then set the values
			if (corridor.direction == Direction.North) 
			{
				startXPos = corridor.startXPos;
				startYPos = corridor.startYPos + corridor.corridorLength;
				//maxLength = rows - startYPos;
			} 
			else if (corridor.direction == Direction.East) 
			{
				startXPos = Random.Range (corridor.startXPos + 8, corridor.startXPos + corridor.corridorLength - 8);
				startYPos = corridor.startYPos + corridor.corridorWidth;
				//maxLength = columns - startXPos;
			}
			else if (corridor.direction == Direction.West) 
			{
				startXPos = Random.Range (corridor.startXPos - 8, corridor.startXPos - corridor.corridorLength + 8);
				startYPos = corridor.startYPos + corridor.corridorWidth; 
				//maxLength = startXPos;
			} 
			maxLength = rows - startYPos;
			break;
		case Direction.East:
			if (corridor.direction == Direction.East) 
			{
				startXPos = corridor.startXPos + corridor.corridorLength;
				startYPos = corridor.startYPos;
				//maxLength = columns - startXPos;
			} 
			else if (corridor.direction == Direction.North) 
			{
				startXPos = corridor.startXPos + corridor.corridorWidth;
				startYPos = Random.Range (corridor.startYPos + 8, corridor.startYPos + corridor.corridorLength - 8);
				//maxLength = rows - startYPos;
			}
			else if (corridor.direction == Direction.South) 
			{
				startXPos = corridor.startXPos + corridor.corridorWidth;
				startYPos = Random.Range (corridor.startYPos - 8, corridor.startYPos - corridor.corridorLength + 8);
				//maxLength = startYPos;
			}
			maxLength = columns - startXPos;
			break;
		case Direction.South:
			if (corridor.direction == Direction.South) 
			{
				startXPos = corridor.startXPos;
				startYPos = corridor.startYPos - corridor.corridorLength;
				//maxLength = startYPos;
			} 
			else if (corridor.direction == Direction.East) 
			{
				startXPos = Random.Range (corridor.startXPos + 8, corridor.startXPos + corridor.corridorLength - 8);
				startYPos = corridor.startYPos;
				//maxLength = columns - startXPos;
			}
			else if(corridor.direction == Direction.West) 
			{
				startXPos = Random.Range (corridor.startXPos - 8, corridor.startXPos - corridor.corridorLength + 8);
				startYPos = corridor.startYPos;
				//maxLength = startXPos;
			}
			maxLength = startYPos;
			break;
		case Direction.West:
			if (corridor.direction == Direction.West) 
			{
				startXPos = corridor.startXPos - corridor.corridorLength;
				startYPos = corridor.startYPos;
				//maxLength = startXPos;
			} 
			else if (corridor.direction == Direction.North) 
			{
				startXPos = corridor.startXPos;
				startYPos = Random.Range (corridor.startYPos + 8, corridor.startYPos + corridor.corridorLength - 8);
				//maxLength = rows - startYPos;
			}
			else if(corridor.direction == Direction.South) 
			{
				startXPos = corridor.startXPos;
				startYPos = Random.Range (corridor.startYPos - corridor.corridorLength + 8, corridor.startYPos - 8);
				//maxLength = startYPos;
			}
			maxLength = startXPos;
			break;
		}
		// We clamp the length of the corridor to make sure it doesn't go off the board.
		corridorLength = Mathf.Clamp(corridorLength, 1, maxLength);
	}
 // returns a dungeon with the previously given config
 public ArrayList generateDungeon()
 {
     Random.seed = (int)(seed*100000.0f);
     while (true)
     {
         ArrayList dungeon = new ArrayList();
         ArrayList roomsMade = new ArrayList();
         while (roomsMade.Count < rooms)
         {
             Room r = new Room();
             r.make ((int)Mathf.Floor(Random.value*width), (int)Mathf.Floor(Random.value*height), (int)Mathf.Floor(Random.value*(maxWidth-minWidth))+minWidth, (int)Mathf.Floor(Random.value*(maxHeight-minHeight))+minHeight);
             if (r.check(dungeon))
             {
                 roomsMade.Add(r);
                 r.addTo (ref dungeon);
             }
         }
         ArrayList corridorsMade = new ArrayList();
         for (int i = 0; i < roomsMade.Count; ++i)
         {
             for (int c = 0; c < roomsMade.Count; ++c)
             {
                 if (i != c)
                 {
                     Corridor cor = new Corridor();
                     cor.setWidth(corridorWidth);
                     cor.make (((Room)roomsMade[i]), ((Room)roomsMade[c]));
                     if (cor.check(dungeon))
                     {
                         corridorsMade.Add(cor);
                         cor.addTo (ref dungeon);
                     }
                 }
             }
         }
         for (int i = 0; i < roomsMade.Count; ++i)
         {
             ((Room)roomsMade[i]).touched = false;
         }
         if (!checkIfDungeonWorks(0, roomsMade, corridorsMade))
             continue;
         Vector2 spawnPos = ((Room)roomsMade[0]).getRandomPos(seed);
         Tile ts = new Tile();
         ts.type = "spawn";
         ts.xPos = (int)spawnPos.x;
         ts.yPos = (int)spawnPos.y;
         dungeon.Add(ts);
         for (int i = 1; i < roomsMade.Count; ++i)
         {
             Vector2 enPos = ((Room)roomsMade[i]).getRandomPos(seed);
             Tile en = new Tile();
             en.type = "enemy";
             en.xPos = (int)enPos.x;
             en.yPos = (int)enPos.y;
             dungeon.Add(en);
         }
         return dungeon;
     }
 }
	void CreateRoomsAndCorridors ()
	{
		// Create the rooms array with a random size.
		rooms = new Room[numRooms.Random];

		// There should be one less corridor than there is rooms.
		corridors = new Corridor[rooms.Length - 1];

		// Create the first room and corridor.
		rooms[0] = new Room ();
		corridors[0] = new Corridor ();

		// Setup the first room, there is no previous corridor so we do not use one.
		rooms[0].SetupRoom(roomWidth, roomHeight, columns, rows);

		// Setup the first corridor using the first room.
		corridors[0].SetupCorridor(rooms[0], corridorLength, roomWidth, roomHeight, columns, rows, true);

		for (int i = 1; i < rooms.Length; i++)
		{
			if((int)(Random.value * 100) % 2 == 0 && (keyCountInLevel < levelKeys ))
			{
				roomHasKey = true;
				Debug.Log("room has Key!");
				keyCountInLevel++;
			}
			else
			{
				roomHasKey = false;
			} 

			// Create a room.
			rooms[i] = new Room ();

			// Setup the room based on the previous corridor.
			rooms[i].SetupRoom (roomWidth, roomHeight, columns, rows, corridors[i - 1], roomHasKey);

			// If we haven't reached the end of the corridors array...
			if (i < corridors.Length)
			{
				// ... create a corridor.
				corridors[i] = new Corridor ();

				// Setup the corridor based on the room that was just created.
				corridors[i].SetupCorridor(rooms[i], corridorLength, roomWidth, roomHeight, columns, rows, false, rooms[i].hasKey);
			}
				

			if (i == rooms.Length-1)
			{
				//add exit to the level
				Vector3 exitPos = new Vector3 (rooms[i].xPos, rooms[i].yPos, 0);
				Instantiate(exit, exitPos, Quaternion.identity);

				Vector3 playerPos = new Vector3 (rooms[0].xPos, rooms[0].yPos, 0);
				player.transform.position = playerPos;
				Debug.Log(player.transform.position);
			}
		}

	}
Exemplo n.º 42
0
 private static void MakewholeCor()
 {
     var bounds = new Rectangle(minX, minY, maxX - minX, maxY - minY);
     corridor = new Corridor(_game, new Vector2(bounds.Location.X, bounds.Location.Y)
                               , _colour, _lightcolour, halfwidth, bounds);
     _level.Roomlist.Add(corridor);
 }
Exemplo n.º 43
0
 protected void RemoveCorridor(Corridor corridor)
 {
     allCorridors.Remove (corridor);
     dungeonGenerator.cellTypeGrid[corridor.location.x, corridor.location.y, corridor.location.z] = CellType.Empty;
 }
Exemplo n.º 44
0
	void spawnGate(Corridor corridor, GameObject gate)
	{
		switch(corridor.direction)
		{
		case Direction.North:
			ChildOfBoardHolder = Instantiate(gate, new Vector3(corridor.startXPos+3,corridor.startYPos+corridor.corridorLength-2,0), Quaternion.Euler(0,0,90)) as GameObject;
			ChildOfBoardHolder.transform.SetParent (boardHolder.transform);
			break;
		case Direction.East:
			ChildOfBoardHolder = Instantiate(gate, new Vector3(corridor.startXPos+corridor.corridorLength-7,corridor.startYPos+3,0), Quaternion.identity) as GameObject;
			ChildOfBoardHolder.transform.SetParent (boardHolder.transform);
			break;
		case Direction.South:
			ChildOfBoardHolder = Instantiate(gate, new Vector3(corridor.startXPos+3,corridor.startYPos-corridor.corridorLength+4,0), Quaternion.Euler(0,0,90)) as GameObject;
			ChildOfBoardHolder.transform.SetParent (boardHolder.transform);
			break;
		case Direction.West:
			ChildOfBoardHolder = Instantiate(gate, new Vector3(corridor.startXPos-corridor.corridorLength+3,corridor.startYPos+3,0), Quaternion.identity) as GameObject;
			ChildOfBoardHolder.transform.SetParent (boardHolder.transform);
			break;
		}
	}
Exemplo n.º 45
0
	bool doRoomsOverlapCorridor(Corridor alreadyPlaced, Room toBePlaced)
	{
		bool doesOverlap = false;
		//finds the direction of the corridor and makes the correct rectangle
		switch(alreadyPlaced.direction)
		{
		case Direction.North:
			alreadyPlacedRect = new Rect (alreadyPlaced.startXPos, alreadyPlaced.startYPos, alreadyPlaced.corridorWidth+2, alreadyPlaced.corridorLength);
			break;
		case Direction.East:
			alreadyPlacedRect = new Rect (alreadyPlaced.startXPos, alreadyPlaced.startYPos, alreadyPlaced.corridorLength, alreadyPlaced.corridorWidth+2);
			break;
		case Direction.South:
			alreadyPlacedRect = new Rect (alreadyPlaced.startXPos, alreadyPlaced.EndPositionY, alreadyPlaced.corridorWidth+2, alreadyPlaced.corridorLength);
			break;
		case Direction.West:
			alreadyPlacedRect = new Rect (alreadyPlaced.EndPositionX, alreadyPlaced.startYPos, alreadyPlaced.corridorLength, alreadyPlaced.corridorWidth+2);
			break;
		}

		//makes the room rectangle
		toBePlacedRect = new Rect (toBePlaced.xPos-2, toBePlaced.yPos-2, toBePlaced.roomWidth+3, toBePlaced.roomHeight+3);

		//checks to see if the toBePlaced rectangle overlaps the already placed
		if (alreadyPlacedRect.Overlaps (toBePlacedRect)) 
		{
			doesOverlap = true;
		}
		//if previous did not register then checks vise versa
		else if (toBePlacedRect.Overlaps (alreadyPlacedRect)) 
		{
			doesOverlap = true;
		} 
		else 
		{
			//Lastly if code gets here then it individually checks each tile and checks if it is within the other rect
			for (float i = toBePlacedRect.x; i <= toBePlacedRect.x + toBePlacedRect.width; i++) {
				for (float j = toBePlacedRect.y; j <= toBePlacedRect.y + toBePlacedRect.height; j++) {
					if (alreadyPlacedRect.Contains (new Vector2 (i, j))) {
						doesOverlap = true;
						break;
					}
				}
			}
		}
		return doesOverlap;
	}
Exemplo n.º 46
0
        // Assumes positon is at the end of the corridor
        private IntPair MovePositionFromCorridorBeginningToBottomLeftEndRoom(IntPair position, Corridor corridor)
        {
            int offset;
            switch (corridor.direction)
            {
                case Direction.WEST:
                    offset = corridor.exitRoom.size.x;
                    break;
                case Direction.SOUTH:
                    offset = corridor.exitRoom.size.y;
                    break;
                default:
                    offset = 1;
                    break;
            }

            return position.Move(corridor.direction, offset);
        }
Exemplo n.º 47
0
Arquivo: Room.cs Projeto: Porkka/CDIO4
    public bool ConnectWith(Room room)
    {
        if (Map.DEBUG)
        {
            Debug.Log("Connecting rooms...");
        }

        bool retVal = false;
        Tile myCenter = this.CenterTile;
        Tile hesCenter = room.CenterTile;

        if (myCenter != null && hesCenter != null)
        {
            Corridor c = new Corridor(myCenter, hesCenter);

            if (Map.DEBUG)
            {
                Debug.Log(string.Format("Created corridor from {0},{1} to {2},{3}...", c.StartsFrom.worldPosition.x, c.StartsFrom.worldPosition.y, c.EndsTo.worldPosition.x, c.EndsTo.worldPosition.y));
            }

            this.corridors.Add(c);
            room.corridors.Add(c);

            retVal = this.connected = room.connected = true;
        }
        else
        {
            if (Map.DEBUG)
            {
                Debug.Log("Room center tiles were null ? Couldn't connect them.");
            }

        }

        return retVal;
    }
Exemplo n.º 48
0
	public void SetUpAppendedCorridor(Corridor corridor, IntRange length, IntRange roomWidth, IntRange roomHeight, int columns, int rows, int xStart, int yStart)
	{	
		Direction oppositeDirection = (Direction)(((int)corridor.direction + 2) % 4);

		// If this is noth the first corridor and the randomly selected direction is opposite to the previous corridor's direction...
		if (direction == oppositeDirection)
		{
			// Rotate the direction 90 degrees clockwise (North becomes East, East becomes South, etc).
			// This is a more broken down version of the opposite direction operation above but instead of adding 2 we're adding 1.
			// This means instead of rotating 180 (the opposite direction) we're rotating 90.
			int directionInt = (int)direction;
			directionInt++;
			directionInt = directionInt % 4;
			direction = (Direction)directionInt;

		}

		// Set a random length.
		corridorLength = length.Random;

		// Create a cap for how long the length can be (this will be changed based on the direction and position).
		int maxLength = length.m_Max;

		switch (direction)
		{
		case Direction.North:
			startXPos = xStart - corridorWidth;
			startYPos = yStart - corridorWidth + 1;
			maxLength = rows - startYPos - roomHeight.m_Min;
			//maxLength = rows - startYPos;
			break;
		case Direction.East:

			if (oppositeDirection == Direction.North || oppositeDirection == Direction.South)
				startXPos = xStart - corridorWidth + 1;	
			else
				startXPos = xStart + 1;

			startYPos = yStart - corridorWidth;
			maxLength = columns - startXPos - roomWidth.m_Min;
			//maxLength = columns - startXPos;
			break;
		case Direction.South:
			startXPos = xStart - corridorWidth;
			startYPos = yStart;
			maxLength = startYPos - roomHeight.m_Min;
			//maxLength = startYPos;
			break;
		case Direction.West:

			if (corridor.direction == Direction.North || corridor.direction == Direction.South)
				startXPos = xStart;	
			else
				startXPos = xStart + 1;

			startYPos = yStart - corridorWidth;
			maxLength = startXPos - roomWidth.m_Min;
			//maxLength = columns - startXPos;
			break;
		}

		// Set a random length, ensure the length is greater than corridor width
		// for proper corridor appending
		do
		{
			corridorLength = length.Random;
		}
		while(corridorLength <= corridorWidth + 1);

		// We clamp the length of the corridor to make sure it doesn't go off the board.
		corridorLength = Mathf.Clamp(corridorLength, 1, maxLength);
	}
Exemplo n.º 49
0
 // Assumes position is at end of starting room
 // Returns the position where the corridor ends
 private IntPair GenerateTilesForCorridor(Corridor corridor, IntPair position, Dictionary<IntPair, Tile> allTiles)
 {
     for (int i = 0; i < corridor.length; ++i)
     {
         position = position.Move(corridor.direction);
         CreateOrUpdateTileIn(position, allTiles);
     }
     return position;
 }
Exemplo n.º 50
0
    void CreateRoomsAndCorridors()
    {
        // Create the rooms array with a random size.
        rooms = new Room[numRooms.Random];

        // There should be one less corridor than there is rooms.
        corridors = new Corridor[rooms.Length - 1];

        // Create the first room and corridor.
        rooms[0] = new Room();
        corridors[0] = new Corridor();

        // Setup the first room, there is no previous corridor so we do not use one.
        rooms[0].SetupRoom(roomWidth, roomHeight, columns, rows);

        // Setup the first corridor using the first room.
        corridors[0].SetupCorridor(rooms[0], corridorLength, roomWidth, roomHeight, columns, rows, true);

        Vector3 playerPos = new Vector3(rooms[0].xPos, rooms[0].yPos, 0);
        GameObject go = Instantiate(player, playerPos, Quaternion.identity) as GameObject;
        go.name = "player";

        if (go == null) Debug.Log("Null");
        //assign player to camera
        camcon.assignPlayer(go);

        exitRoom = 0;

        for (int i = 1; i < rooms.Length; i++)
        {

            // Create a room.
            rooms[i] = new Room();

            // Setup the room based on the previous corridor.
            rooms[i].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[i - 1]);

            // If we haven't reached the end of the corridors array...
            if (i < corridors.Length)
            {
                // ... create a corridor.
                corridors[i] = new Corridor();

                // if  room y + height + corridorLength.maxLength + roomHeight.maxY > startRoom.y   ** Can't go north
                //if(rooms[i].yPos +

                //(room.yPos < (this.yPos + this.roomHeight) || (room.yPos + room.roomHeight) > (this.yPos))  && ((room.xPos  < this.xPos + this.roomWidth) || room.xPos + room.roomWidth > this.xPos)

                // Setup the corridor based on the room that was just created.
                bool corridorFeasible = true;
                do
                {
                    corridors[i].SetupCorridor(rooms[i], corridorLength, roomWidth, roomHeight, columns, rows, false);
                    switch(corridors[i].direction)
                    {
                        case Direction.North:
                            corridorFeasible = ((rooms[i].yPos + rooms[i].roomHeight + corridorLength.m_Max + roomHeight.m_Max < rooms[0].yPos || rooms[0].yPos + rooms[0].roomHeight < rooms[i].yPos) || ((corridors[i].startXPos - roomWidth.m_Max < rooms[0].xPos) || (corridors[i].startXPos + 1 + roomWidth.m_Max > rooms[0].xPos + roomWidth.m_Max)));
                            break;
                        case Direction.South:
                            corridorFeasible = ((rooms[i].yPos - corridorLength.m_Max - roomHeight.m_Max < rooms[0].yPos + rooms[0].roomHeight || rooms[0].yPos > rooms[i].yPos + rooms[i].roomHeight) || ((corridors[i].startXPos - roomWidth.m_Max > rooms[0].xPos) || (corridors[i].startXPos + 1 + roomWidth.m_Max > rooms[0].xPos + roomWidth.m_Max)));
                            break;
                        case Direction.East:
                            corridorFeasible = ((rooms[i].xPos + rooms[i].roomWidth + corridorLength.m_Max + roomWidth.m_Max < rooms[0].xPos) || rooms[0].xPos + rooms[0].roomWidth > rooms[i].xPos || ((corridors[i].startYPos - roomHeight.m_Max > rooms[0].yPos) || (corridors[i].startYPos + 1 + roomHeight.m_Max > rooms[0].yPos + roomHeight.m_Max)));
                            break;
                        case Direction.West:
                            corridorFeasible = ((rooms[i].xPos - corridorLength.m_Max - roomWidth.m_Max < rooms[0].xPos + rooms[0].roomWidth) || rooms[0].xPos + rooms[0].roomWidth < rooms[i].xPos || ((corridors[i].startYPos - roomHeight.m_Max > rooms[0].yPos) || (corridors[i].startYPos + 1 + roomHeight.m_Max > rooms[0].yPos + roomHeight.m_Max)));
                            break;
                    }
                }
                while(!corridorFeasible);
            }

                // Spawn mobs in said room
                mobcon.SpawnMob(0, rooms[i].xPos + 1, rooms[i].yPos + 1);
                mobcon.SpawnMob(0, rooms[i].xPos + rooms[i].roomWidth - 2, rooms[i].yPos);
                mobcon.SpawnMob(0, rooms[i].xPos, rooms[i].yPos + rooms[i].roomHeight - 2);

                if(Vector3.Distance(new Vector3(rooms[i].xPos,rooms[i].yPos,0),new Vector3(rooms[0].xPos,rooms[0].yPos,0)) > Vector3.Distance(new Vector3(rooms[exitRoom].xPos,rooms[exitRoom].yPos,0),new Vector3(rooms[0].xPos,rooms[0].yPos,0)) ){
                    exitRoom = i;
                }
        }
        SpawnExit();
    }
Exemplo n.º 51
0
	// for a given room finds possible pathways to its neighbors
	public void SearchEdges(Room room, int wall){
		var interval = roomIntervals[wall];
		int i = 1+interval.ToList ().IndexOf (room);
		Room temp;
		int maxI, minI;
		// set up the walls
		if (wall % 2 == 0){ //even
			maxI = 1;
			minI = 3; 
		}
		else { // odd
			maxI = 0; 
			minI = 2;
		}
		float max = room.bounds [maxI];
		float min = room.bounds [minI];

		bool search = true;
		Corridor cord;
		while (search && i < interval.Length){
			temp = interval[i];
			if (max >= temp.bounds[minI] && temp.bounds[maxI] >= min){ // check if straight shot is possible
			var test = TestStraight (ref max, ref min,temp.bounds[maxI],temp.bounds[minI]); // test the edge for straight shot
				if (test){
					cord = new Corridor(Corridor_prefab, room.index,temp.index,max, min, 
					                          room.bounds[wall], temp.bounds[(wall+2)%4],wall);
					if (roomsList[room.index].corridors[wall] == null){
						roomsList[room.index].corridors[wall] = cord;
						roomsList[temp.index].corridors[(wall+2)%4] = cord;
						//cord.BuildCorridor(); // for testing / intersect

					}

				search = false;	// done searching
				//cord.BuildCorridor(); // MST location

				}
				else{
					if (max-min < delta){// no possible corridors found
						search = false; 
					}
				}
			}
			else{ // look for diagonal corridors
				cord = DiagCord(max, min,maxI, minI, room, temp,i, wall);
			}
			i+=1;
		}
	}
Exemplo n.º 52
0
	void spawnAudioTrigger(Corridor corridor, GameObject audioTrigger)
	{
		switch(corridor.direction)
		{
		case Direction.North:
			ChildOfBoardHolder = Instantiate(audioTrigger, new Vector3(corridor.startXPos+3,corridor.startYPos+3,0), Quaternion.identity) as GameObject;
			ChildOfBoardHolder.transform.SetParent (boardHolder.transform);
			break;
		case Direction.East:
			ChildOfBoardHolder = Instantiate(audioTrigger, new Vector3(corridor.startXPos+3,corridor.startYPos+3,0), Quaternion.Euler(0,0,90)) as GameObject;
			ChildOfBoardHolder.transform.SetParent (boardHolder.transform);
			break;
		case Direction.South:
			ChildOfBoardHolder = Instantiate(audioTrigger, new Vector3(corridor.startXPos+3,corridor.startYPos-4,0), Quaternion.identity) as GameObject;
			ChildOfBoardHolder.transform.SetParent (boardHolder.transform);
			break;
		case Direction.West:
			ChildOfBoardHolder = Instantiate(audioTrigger, new Vector3(corridor.startXPos-4,corridor.startYPos+3,0), Quaternion.Euler(0,0,90)) as GameObject;
			ChildOfBoardHolder.transform.SetParent (boardHolder.transform);
			break;
		}
	}
Exemplo n.º 53
0
 private void BeginGame()
 {
     corridorInstance = Instantiate (corridorPrefab) as Corridor;
     corridorInstance.Generate ();
 }
Exemplo n.º 54
0
 protected void AddCorridor(Corridor corridor)
 {
     allCorridors.Add (corridor);
     dungeonGenerator.cellTypeGrid[corridor.location.x, corridor.location.y, corridor.location.z] = CellType.Corridor;
 }
Exemplo n.º 55
0
    protected bool CorridorCanGo(Corridor corridor, Dir direction)
    {
        CellType testType = CellType.Blocked;

        if (direction == Dir.North) {

            if (corridor.location.z < dungeonGenerator.numCellsZ - 3) {

                testType = dungeonGenerator.cellTypeGrid[corridor.location.x, corridor.location.y, corridor.location.z + 2];
            }
        }
        else if (direction == Dir.South) {

            if (corridor.location.z > 2) {

                testType = dungeonGenerator.cellTypeGrid[corridor.location.x, corridor.location.y, corridor.location.z - 2];
            }
        }
        else if (direction == Dir.East) {

            if (corridor.location.x < dungeonGenerator.numCellsX - 3) {

                testType = dungeonGenerator.cellTypeGrid[corridor.location.x + 2, corridor.location.y, corridor.location.z];
            }
        }
        else if (direction == Dir.West) {

            if (corridor.location.x > 2) {

                testType = dungeonGenerator.cellTypeGrid[corridor.location.x - 2, corridor.location.y, corridor.location.z];
            }
        }

        if (CorridorCanReplace (testType)) {

            return true;
        }

        return false;
    }
Exemplo n.º 56
0
        private Dictionary<IntPair, Tile> GenerateTiles(Corridor[] corridors)
        {
            Dictionary<IntPair, Tile> allTiles = new Dictionary<IntPair, Tile>();

            // Create starting room from first corridor
            IntPair position = this.startingPoint;
            GenerateTilesForRoom(corridors[0].entranceRoom, position, allTiles);

            SetStartingTile(allTiles);

            foreach (Corridor corridor in corridors)
            {
                //  Select wall in the direction and choose one tile to start the corridor
                position = MovePositionToBorderOfRoomInGivenDirection(position, corridor.entranceRoom, corridor.direction);
                //  Generate corridor from that tile, in the direction of corridor
                position = GenerateTilesForCorridor(corridor, position, allTiles);
                //  At the end of corridor, choose a random x/y position from exit room
                position = MovePositionFromCorridorBeginningToBottomLeftEndRoom(position, corridor);
                //  Generate room from top-left corner
                GenerateTilesForRoom(corridor.exitRoom, position, allTiles);

            }

            SetEndingTile(allTiles);

            return allTiles;
        }
Exemplo n.º 57
0
	void CreateRoomsAndCorridors()
	{
		while (needRoomsAndCorridorsCreation == true) 
		{
			// Create the rooms array with a random size.
			rooms = new Room[numRooms.Random];

			//Non IntRange representation of how many rooms there are
			int numbRooms = rooms.Length;

			// There should be one less corridor than there is rooms.
			corridors = new Corridor[rooms.Length - 1];
			// There will be a specified number of appending corridor
			aCorridors = new Corridor[rooms.Length - 2];
			//Make dead end corridor array
			deadEndCorridorsArray = new Corridor[corridors.Length];
			// Create the first room and corridor.
			rooms [0] = new Room ();
			corridors [0] = new Corridor ();

			// Setup the first room, there is no previous corridor so we do not use one.
			rooms [0].SetupRoom (roomWidth, roomHeight, columns, rows);

			// Setup the first corridor using the first room.
			corridors [0].SetupCorridor (rooms [0], corridorLength, roomWidth, roomHeight, columns, rows, true);

			// Set up second room. Check for overlap is not necessary
			rooms [1] = new Room ();
			rooms [1].SetupRoom (roomWidth, roomHeight, columns, rows, corridors [0]);

			// Set up the rest of the rooms and corridors, checking for overlaps

			for (int i = 2; i < rooms.Length; i++) {
				bool goodRoomPlacement = false;
				bool goodCorridorPlacement = false;
				bool goodAppCorridorPlacement = false;
				bool goodDeadEndCorridorPlacement = false;
				//bool goodCorridorNotOverlapRoomPlacement = false;
				bool goodRoomNotOverlapCorridorPlacement = false;
				//bool roomOverlapsCorridor = false;
				//bool roomOverlapsAppCorridor = false;
				//bool roomOverlapsDeadEndCorridor = false;
				bool makeDeadEndCorridor = true;

				//If generation has tried different corridor/room placements exceeding the number of rooms there are
				if (triedCounter >= numbRooms * 2) {
					//Then reload the level
					//reloadLevelNeeded = true;
					//SceneManager.LoadScene (3);
					break;
				}
            




				// If room overlaps with any other rooms, create entirely new corridor leaving from the last created room
				while (!goodRoomPlacement && !goodCorridorPlacement && !goodDeadEndCorridorPlacement && !goodAppCorridorPlacement && !goodRoomNotOverlapCorridorPlacement) {
					bool appendCorridor = false;
					// Create test corridor and room
					Corridor corridorToBePlaced = new Corridor ();
					Corridor corridorToAppend = new Corridor ();
					if (numAppend < rooms.Length - 1)
						appendCorridor = true;

					//If a room in the array is null then there was an error with generation. Restart the scene
					if (rooms [i - 1] == null) {
						//reloadLevelNeeded = true;
						//SceneManager.LoadScene (3);
						break;
					}

					//Set tried counter to 0 and enter into while loop with placementNeeded as true
					triedCounter = 0;
					placementNeeded = true;
					//Stays in this loop until a good placement or the amount of tries has been exceeded
					while (placementNeeded == true) {
						triedCounter++;
						if (triedCounter >= numbRooms * 2)
							break;
						//Create the corridor


						//Make the corridor
						corridorToBePlaced.SetupCorridor (rooms [i - 1], corridorLength, roomWidth, roomHeight, columns, rows, false);

						//Stay in this loop until the corridor is longer than the minimum length or until tries are exhausted
						while (corridorToBePlaced.corridorLength < minCorridorLength) {
							triedCounter++;

							corridorToBePlaced.SetupCorridor (rooms [i - 1], corridorLength, roomWidth, roomHeight, columns, rows, false);
							if (triedCounter >= numbRooms * 2)
								break;
						}
						if (triedCounter >= numbRooms * 2)
							break;
						if (corridorToBePlaced.corridorLength < minCorridorLength) {
							//Do nothing
						} else {
							//Check to see if it overlaps any rooms/corridors
							for (int j = 0; j < i; j++) {
								//Check if it overlaps a regular corridor
								if (corridors [j] != null) {
									if (doCorridorsOverlapCorridor (corridors [j], corridorToBePlaced))
										break;
								}
								//Check if it overlaps with an appended corridor
								if (j < aCorridors.Length) {
									if (aCorridors [j] != null) {
										if (doCorridorsOverlapCorridor (aCorridors [j], corridorToBePlaced))
											break;
									}
								}
								//check if it overlaps with another dead end corridor
								if (deadEndCorridorsArray [j] != null) {
									if (doCorridorsOverlapCorridor (deadEndCorridorsArray [j], corridorToBePlaced))
										break;
								}
								// If last room has been checked and room to be placed doesn't overlap with it...
								if (j == (i - 1)) {
									//Dead end corridorto be placed doesn't overlap with any existing rooms, so exit while loop
									goodCorridorPlacement = true;
									//Exit the loop since a good placement has been achieved
									placementNeeded = false;
								}								
							}
						}
					}
					if (triedCounter >= numbRooms * 2)
						break;
				
					//triedCounter++;
					Room roomToBePlaced = new Room ();

					if (appendCorridor) {
						triedCounter = 0;
						placementNeeded = true;

						while (placementNeeded == true) {
							triedCounter++;
							if (triedCounter >= numbRooms * 2)
								break;
							//Create the Corridor


							//create the corridor 
							corridorToAppend.SetUpAppendedCorridor (corridorToBePlaced, corridorLength, roomWidth, roomHeight, columns, rows, corridorToBePlaced.EndPositionX, corridorToBePlaced.EndPositionY);

							//Stay in this loop until the corridor is longer than the minimum length or until tries are exhausted
							while (corridorToAppend.corridorLength < minCorridorLength) {
								triedCounter++;

								corridorToAppend.SetUpAppendedCorridor (corridorToBePlaced, corridorLength, roomWidth, roomHeight, columns, rows, corridorToBePlaced.EndPositionX, corridorToBePlaced.EndPositionY);
								if (triedCounter >= numbRooms * 2)
									break;
							}
							if (triedCounter >= numbRooms * 2)
								break;
							//Checks to see if the appended corridor overlaps with the dead end corridor that is to be placed
							//if(doCorridorsOverlapCorridor(deadEndCorridor,corridorToAppend))
							//	break;
						
							if (corridorToAppend.corridorLength < minCorridorLength) {
								//break;
							} else {
								//Check to see if it overlaps with any rooms/corridors
								for (int j = 0; j < i; j++) {
									//checks to see if the appending corridor overlaps with rooms
									if (doCorridorsOverlapRooms (rooms [j], corridorToAppend)) {
										break;
									}
									//checks to see if the appending corridor overlaps with regular corridors
									if (corridors [j] != null) {
										if (doCorridorsOverlapCorridor (corridors [j], corridorToAppend))
											break;
									}
									//checks to see if it overlaps with the other appending corridors
									if (j < aCorridors.Length) {
										if (aCorridors [j] != null) {
											if (doCorridorsOverlapCorridor (aCorridors [j], corridorToAppend))
												break;
										}
									}
									//checks to see if it overlaps with any dead end corridors
									if (deadEndCorridorsArray [j] != null) {
										if (doCorridorsOverlapCorridor (deadEndCorridorsArray [j], corridorToAppend))
											break;
									}

									if (j == (i - 1)) {
										// Room to be placed doesn't overlap with any existing rooms, so exit while loop
										goodAppCorridorPlacement = true;
										placementNeeded = false;
									}
								}
							}
						}
						if (goodAppCorridorPlacement == false)
							break;
						if (triedCounter >= numbRooms * 2)
							break;
						triedCounter = 0;
						placementNeeded = true;
						//Stays in this loop until a good placement or the amount of tries has been exceeded
						while (placementNeeded == true) {
							triedCounter++;
							if (triedCounter >= numbRooms * 2)
								break;
							//Create Room
							roomToBePlaced.SetupRoom (roomWidth, roomHeight, columns, rows, corridorToAppend);
							//if(doRoomsOverlapCorridor(deadEndCorridor,roomToBePlaced))
							//{
							//	break;
							//}
							//Check to see if it overlaps any corridors
							for (int j = 0; j < i; j++) {
								//checks to see if the room overlaps with regular corridors
								if (corridors [j] != null) {
									if (doRoomsOverlapCorridor (corridors [j], roomToBePlaced))
										break;
								}
								//checks to see if it overlaps any appending corridors
								if (j < aCorridors.Length) {
									if (aCorridors [j] != null) {
										if (doRoomsOverlapCorridor (aCorridors [j], roomToBePlaced))
											break;
									}
								}
								//checks to see if it overlaps with any dead end corridors
								if (deadEndCorridorsArray [j] != null) {
									if (doRoomsOverlapCorridor (deadEndCorridorsArray [j], roomToBePlaced))
										break;
								}
								if (j == (i - 1)) {
									// Room to be placed doesn't overlap with any existing rooms, so exit while loop
									goodRoomNotOverlapCorridorPlacement = true;
									placementNeeded = false;
								}
							}
						}
						if (goodRoomNotOverlapCorridorPlacement == false)
							break;
						if (triedCounter >= numbRooms * 2)
							break;
					} else {
						triedCounter = 0;
						placementNeeded = true;
						//Stays in this loop until a good placement or the amount of tries has been exceeded
						while (placementNeeded == true) {
							triedCounter++;
							if (triedCounter >= numbRooms * 2)
								break;
							//Create Room
							roomToBePlaced.SetupRoom (roomWidth, roomHeight, columns, rows, corridorToAppend);
							//if(doRoomsOverlapCorridor(deadEndCorridor,roomToBePlaced))
							//{
							//	break;
							//}
							//Check to see if it overlaps any corridors
							for (int j = 0; j < i; j++) {
								if (corridors [j] != null) {
									if (doRoomsOverlapCorridor (corridors [j], roomToBePlaced))
										break;
								}
								if (j < aCorridors.Length) {
									if (aCorridors [j] != null) {
										if (doRoomsOverlapCorridor (aCorridors [j], roomToBePlaced))
											break;
									}
								}
								if (deadEndCorridorsArray [j] != null) {
									if (doRoomsOverlapCorridor (deadEndCorridorsArray [j], roomToBePlaced))
										break;
								}
								if (j == (i - 1)) {
									// Room to be placed doesn't overlap with any existing rooms, so exit while loop
									goodRoomNotOverlapCorridorPlacement = true;
									placementNeeded = false;
								}
							}
						}
						if (goodRoomNotOverlapCorridorPlacement == false)
							break;
						if (triedCounter >= numbRooms * 2)
							break;
					}

					// Loop over all other rooms created, except for one to be placed
					for (int j = 0; j < i; j++) {

						// If room to be placed overlaps with j-th room...
						if (doRoomsOverlap (rooms [j], roomToBePlaced)) {
							/* No need to check other rooms, so break from
							 * for loop and setup a new corridor and room */
							break;
						} 


						// If last room has been checked and room to be placed doesn't overlap with it...
						if (j == (i - 1)) {
							// Room to be placed doesn't overlap with any existing rooms, so exit while loop
							goodRoomPlacement = true;
						}
					}
					//If there are no good room placements then break here and start over
					if (goodRoomPlacement == false)
						break;
				
					//Break out of loop if genertion has tried generating corridors/rooms more than the number of rooms
					if (triedCounter >= numbRooms * 2)
						break;

					Corridor deadEndCorridor = new Corridor ();
					roll = Random.Range (0, 100);
					if (roll <= DeadEndChance) {
						makeDeadEndCorridor = true;
						triedCounter = 0;
						placementNeeded = true;
						//Stays in this loop until a good placement or the amount of tries has been exceeded
						while (placementNeeded == true) {
							triedCounter++;
							if (triedCounter >= numbRooms * 2)
								break;
							//Make the corridor

							deadEndCorridor.SetupDeadEndCorridor (corridorToAppend, corridorLength, roomWidth, roomHeight, columns, rows, corridorToBePlaced.startXPos, corridorToBePlaced.startYPos);
							bool deadEndOverlaps = false;

							if (doCorridorsOverlapCorridor (corridorToBePlaced, deadEndCorridor))
								deadEndOverlaps = true;
							
							if (doCorridorsOverlapRooms (roomToBePlaced, deadEndCorridor))
								deadEndOverlaps = true;

							//If dead end corridor overlaps
							if (deadEndOverlaps == true) {
								
							} 
							//else if the dead end corridor does not overlap with currently placing corridor or room
							//then check with the rest of the arrays
							else {
								//Check placement with all other corridors/rooms
								for (int j = 0; j < i; j++) {
									//Check if it overlaps a room
									if (doCorridorsOverlapRooms (rooms [j], deadEndCorridor)) {
										break;
									}
									//Check if it overlaps a regular corridor
									if (corridors [j] != null) {
										if (doCorridorsOverlapCorridor (corridors [j], deadEndCorridor))
											break;
									}
									//Check if it overlaps with an appended corridor
									if (j < aCorridors.Length) {
										if (aCorridors [j] != null) {
											if (doCorridorsOverlapCorridor (aCorridors [j], deadEndCorridor))
												break;
										}
									}
									//check if it overlaps with another dead end corridor
									if (deadEndCorridorsArray [j] != null) {
										if (doCorridorsOverlapCorridor (deadEndCorridorsArray [j], deadEndCorridor))
											break;
									}
									// If last room has been checked and room to be placed doesn't overlap with it...
									if (j == (i - 1)) {
										//Dead end corridorto be placed doesn't overlap with any existing rooms, so exit while loop
										goodDeadEndCorridorPlacement = true;
										placementNeeded = false;
									}								
								}
							}
						}
					} else {
						goodDeadEndCorridorPlacement = true;
					}
					if (triedCounter >= numbRooms * 2)
						break;
				



					// Room doesn't overlap with any other rooms, so add corridor and room to their arrays
					if (goodRoomPlacement && goodCorridorPlacement && goodDeadEndCorridorPlacement && goodAppCorridorPlacement && goodRoomNotOverlapCorridorPlacement) {
						//If room is good, then reset the tried counter
						triedCounter = 0;

						//Put the well placed corridor in the corridors array
						corridors [i - 1] = corridorToBePlaced;

						//Put the well placed appended corridor in the their array
						if (appendCorridor) {
							if (numAppend < aCorridors.Length) {
								aCorridors [numAppend] = corridorToAppend;
								numAppend++;
							}
						}
						//Put the well placed room in the room array
						rooms [i] = roomToBePlaced;

						//Put the well placed dead end corridor in their array 
						if (makeDeadEndCorridor)
							deadEndCorridorsArray [i - 1] = deadEndCorridor;
						
					}

					//Instantiates player in the i-th/2 room created
					//Cast as int so condition is always reachable
					/*
					if (i == (int)(rooms.Length * .5f)) {


						Vector3 playerTeleportPlatPos = new Vector3 (rooms [0].xPos-38f, rooms [0].yPos, 0);//Puts the teleporter in the hub
						ChildOfBoardHolder =  Instantiate (playerTeleportPlat, playerTeleportPlatPos, Quaternion.identity) as GameObject;
						ChildOfBoardHolder.transform.SetParent (boardHolder.transform);

					}
					/*
					if (i == (int)(rooms.Length - 1)) {
						if (rooms [rooms.Length - 1] != null) {
							Vector3 teleporterPos = new Vector3 (rooms [rooms.Length - 1].xPos, rooms [rooms.Length - 1].yPos, 0);
							ChildOfBoardHolder =  Instantiate (teleporter, teleporterPos, Quaternion.identity) as GameObject;
							ChildOfBoardHolder.transform.SetParent (boardHolder.transform);
						}
					}*/
				}
			}

			//Need to check if any rooms or corridors are null, indicating bad generation
			for (int i = 0; i < rooms.Length; i++) {
				if (rooms [i] == null) {
					numAppend = 0;
					triedCounter = 0;
					needRoomsAndCorridorsCreation = true;
					break;
				} else if (i == rooms.Length - 1 && rooms [i] != null)
					needRoomsAndCorridorsCreation = false;

			}
			for (int i = 0; i < corridors.Length; i++) {
				
				if (corridors [i] == null) {
					numAppend = 0;
					triedCounter = 0;
					needRoomsAndCorridorsCreation = true;
					break;
				} else if (i == corridors.Length - 1 && corridors [i] != null) {
					needRoomsAndCorridorsCreation = false;
				}
			}
			for (int i = 0; i < aCorridors.Length; i++) {
				if (aCorridors [i] == null) {
					numAppend = 0;
					triedCounter = 0;
					needRoomsAndCorridorsCreation = true;
					break;
				} else if (i == aCorridors.Length - 1 && aCorridors [i] != null)
					needRoomsAndCorridorsCreation = false;

			}
		}
	}
Exemplo n.º 58
0
    protected void GenerateCorridor(CellLocation location)
    {
        Corridor corridor = new Corridor (location);

        AddCorridor (corridor);

        Dir wayToGo = Dir.None;
        List<Dir> possibleDirections = new List<Dir> ();

        if (CorridorCanGo (corridor, Dir.North)) possibleDirections.Add (Dir.North);
        if (CorridorCanGo (corridor, Dir.South)) possibleDirections.Add (Dir.South);
        if (CorridorCanGo (corridor, Dir.East)) possibleDirections.Add (Dir.East);
        if (CorridorCanGo (corridor, Dir.West)) possibleDirections.Add (Dir.West);

        if (possibleDirections.Count > 0) {

            int randomIndex = Random.Range (1, possibleDirections.Count) - 1;
            wayToGo = possibleDirections[randomIndex];
        }

        if (wayToGo != Dir.None) {

            CellLocation newLocation;
            CellLocation middleLocation;
            Corridor middleCorridor;

            if (wayToGo == Dir.North) {

                newLocation = new CellLocation(location.x, location.y, location.z + 2);
                middleLocation = new CellLocation(location.x, location.y, location.z + 1);
            }
            else if (wayToGo == Dir.South) {

                newLocation = new CellLocation(location.x, location.y, location.z - 2);
                middleLocation = new CellLocation(location.x, location.y, location.z - 1);
            }
            else if (wayToGo == Dir.East) {

                newLocation = new CellLocation(location.x + 2, location.y, location.z);
                middleLocation = new CellLocation(location.x + 1, location.y, location.z);
            }
            else {

                newLocation = new CellLocation(location.x - 2, location.y, location.z);
                middleLocation = new CellLocation(location.x - 1, location.y, location.z);
            }

            middleCorridor = new Corridor (middleLocation);
            AddCorridor (middleCorridor);

            GenerateCorridor (newLocation);

        } else {

            StartNewCorridor ();
        }
    }
Exemplo n.º 59
0
	void CreateRoomsAndCorridors()
	{
		// Create the rooms array with a random size.
		rooms = new Room[numRooms.Random];

		// There should be one less corridor than there is rooms.
		corridors = new Corridor[rooms.Length - 1];

		// Create the first room and corridor.
		rooms[0] = new Room();
		corridors[0] = new Corridor();

		// Setup the first room, there is no previous corridor so we do not use one.
		rooms[0].SetupRoom(roomWidth, roomHeight, columns, rows);

		// Setup the first corridor using the first room.
		corridors[0].SetupCorridor(rooms[0], corridorLength, roomWidth, roomHeight, columns, rows, true);

		for (int i = 1; i < rooms.Length; i++)
		{
			// Create a room.
			rooms[i] = new Room();

			// Setup the room based on the previous corridor.
			rooms[i].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[i - 1]);

			// If we haven't reached the end of the corridors array...
			if (i < corridors.Length)
			{
				// ... create a corridor.
				corridors[i] = new Corridor();

				// Setup the corridor based on the room that was just created.
				corridors[i].SetupCorridor(rooms[i], corridorLength, roomWidth, roomHeight, columns, rows, false);
			}
		}

	}