Beispiel #1
0
    private bool IsWallMatch(int x, int y, OpeningSide openingSide, OpeningSide openingSideMask)
    {
        bool looking4Wall = openingSide == OpeningSide.NONE;

        if (x < 0 || y < 0 || x >= roomMapSize || y >= roomMapSize)
        {
            // There's no rooms outside the boundary, so the room that called this is
            // up against a boundary, so we only match a "wall" room
            return(looking4Wall);
        }
        else
        {
            if (roomMap[x, y] == null)
            {
                // No room next to this wall so we can match anything
                return(true);
            }

            // Need to figure out what wall this room has so we can match it
            RoomSpawner rS   = roomMap[x, y].GetComponent <RoomSpawner>();
            var         temp = rS.typeOfRoom & openingSideMask;

            if (looking4Wall)
            {
                // Looking for a wall
                return(temp == OpeningSide.NONE);
            }
            else
            {
                // Looking for a door
                return(temp != OpeningSide.NONE);
            }
        }
    }
Beispiel #2
0
    private void SpawnARoomIfNeeded(int xDirection, int yDirection, OpeningSide thisOpening, OpeningSide otherOpening, GameObject[] potentialRooms)
    {
        if (typeOfRoom.HasFlag(thisOpening) && CanSpawn(xMap + xDirection, yMap + yDirection))
        {
            List <GameObject> matchingRooms = new List <GameObject>(potentialRooms.Length);

            foreach (GameObject room in potentialRooms)
            {
                if (canPlace(xMap + xDirection, yMap + yDirection, room))
                {
                    matchingRooms.Add(room);
                }
            }

            random = UnityEngine.Random.Range(0, matchingRooms.Count);
            PlaceRoom(xMap + xDirection, yMap + yDirection, Instantiate(matchingRooms[random],
                                                                        transform.position + xDirection * widthOffset + yDirection * heightOffset,
                                                                        Quaternion.identity));
        }
    }