示例#1
0
        public bool SetPosition(DoorStruct adjacentDoor, Room adjacentRoom, ProceduralMapManager mapManager)
        {
            //set references
            this.adjacentDoor = adjacentDoor;
            this.adjacentRoom = adjacentRoom;

            if (adjacentRoom == null || adjacentDoor.doorTransform == null)
            {
                Debug.Log("<color=red>Houston, abbiamo un problema</color>");
            }

            //check this room has a door to adjacent room, and adjust position
            if (CheckDoors() == false)
            {
                return(false);
            }

            //check this room is not inside another room and viceversa
            if (CheckOverlap(mapManager) == false)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        bool CheckDoors()
        {
            //if moving left, check doors on right, else check doors on left
            if (adjacentDoor.direction == CardinalDirection.left || adjacentDoor.direction == CardinalDirection.right)
            {
                entranceDoor.direction = adjacentDoor.direction == CardinalDirection.left ? CardinalDirection.right : CardinalDirection.left;
            }
            //if moving up, check doors on bottom, else check doors on top
            else
            {
                entranceDoor.direction = adjacentDoor.direction == CardinalDirection.up ? CardinalDirection.down : CardinalDirection.up;
            }

            List <DoorStruct> possibleDoors = new List <DoorStruct>();

            //add every possible door (using direction setted before)
            foreach (DoorStruct possibleDoor in doors)
            {
                if (possibleDoor.direction == entranceDoor.direction &&
                    possibleDoor.typeOfDoor != TypeOfDoor.onlyExit)                   //be sure is not OnlyExit, because this one will be an entrance to this room
                {
                    possibleDoors.Add(possibleDoor);
                }
            }

            //if no possible doors, return
            if (possibleDoors.Count <= 0)
            {
                return(false);
            }

            //else get a random door between possibles
            entranceDoor = possibleDoors[Random.Range(0, possibleDoors.Count)];

            //calculate distance and move
            Vector3 fromDoorToAdjacentDoor = adjacentDoor.doorTransform.position - entranceDoor.doorTransform.position;

            transform.position += fromDoorToAdjacentDoor;

            return(true);
        }