Beispiel #1
0
 /// <summary>
 /// When trigger is entered by player, notify the RoomGenerator of this trigger's room
 /// to close this door, and to deactivate the room on the other side of the door.
 /// </summary>
 /// <param name="c">The Player</param>
 void OnTriggerEnter(Collider c)
 {
     if (c.tag == "Player" && !roomGenerator.roomActive) // When this trigger is activated
     {
         gameScript.Doors += 1;
         roomGenerator.RoomEntered(gameScript.GetRoomDirections(thisTrigger));
     }
 }
Beispiel #2
0
    // METHODS
    // Use this for initialization
    void Start()
    {
        triggered  = false;
        discovered = false;
        roomActive = false;

        gameScript = GameObject.Find("GameTrigger").GetComponent <TriggerStartGame>();

        thisRoom = this.transform.parent.gameObject;

        thisRoomCoords     = thisRoom.transform.position;
        thisRoomDirections = gameScript.GetRoomDirections(thisRoom);
        thisRoom.name      = "r" + gameScript.NumRooms;

        gameScript.totalRooms.Add(thisRoom);
        gameScript.totalRoomCoords.Add(thisRoomCoords);
    }
Beispiel #3
0
    /// <summary>
    /// Randomly generate the rooms adjacent to this one, based upon the walls
    /// that have doors within the current room & the surrounding availability.
    /// </summary>
    public void GenerateRooms()
    {
        ArrayList directions = new ArrayList();

        directions.Add(AdjacentDirections.N);
        directions.Add(AdjacentDirections.E);
        directions.Add(AdjacentDirections.S);
        directions.Add(AdjacentDirections.W);

        for (int i = 0; i < directions.Count; i++)
        {
            AdjacentDirections thisDirection     = (AdjacentDirections)directions[i];
            AdjacentDirections oppositeDirection = GetOppositeDirection(thisDirection);
            AdjacentDirections left        = GetLeft(thisDirection);
            AdjacentDirections right       = GetRight(thisDirection);
            Vector3            coordinates = GetDirectionCoords(thisDirection);

            if (gameScript.HasFlag(thisRoomDirections, thisDirection))
            {
                if (!gameScript.ContainsCoordinates(coordinates))
                {
                    ArrayList requiredDirections = GetRequiredDirections(coordinates);

                    ArrayList invalidDirections = GetInvalidDirections(coordinates);
                    bool      canBeHallway      = true;

                    if (invalidDirections.Contains(thisDirection) || requiredDirections.Contains(left) || requiredDirections.Contains(right))
                    {
                        canBeHallway = false;
                    }

                    GameObject newRoom = (GameObject)Instantiate(
                        SelectRoom(oppositeDirection, canBeHallway),
                        coordinates,
                        Quaternion.identity);
                    gameScript.NumRooms++;

                    // Change invalid normal walls to door walls
                    for (int c = 0; c < requiredDirections.Count; c++)
                    {
                        if (!gameScript.HasFlag(gameScript.GetRoomDirections(newRoom), (AdjacentDirections)requiredDirections[c]))
                        {
                            Vector3 location = newRoom.transform.position;
                            location.y = 3.75f;

                            Vector3 triggerLocation = newRoom.transform.position;
                            triggerLocation.y = 3.75f;

                            string directionName = gameScript.GetNameOfDirection((AdjacentDirections)requiredDirections[c]);

                            if ((AdjacentDirections)requiredDirections[c] == AdjacentDirections.N)
                            {
                                location.x        -= 6;
                                location.z        += 10;
                                triggerLocation.z += 7;
                            }

                            else if ((AdjacentDirections)requiredDirections[c] == AdjacentDirections.E)
                            {
                                location.x        += 10;
                                location.z        += 6;
                                triggerLocation.x += 7;
                            }

                            else if ((AdjacentDirections)requiredDirections[c] == AdjacentDirections.S)
                            {
                                location.x        += 6;
                                location.z        -= 10;
                                triggerLocation.z -= 7;
                            }

                            else if ((AdjacentDirections)requiredDirections[c] == AdjacentDirections.W)
                            {
                                location.x        -= 10;
                                location.z        -= 6;
                                triggerLocation.x -= 7;
                            }

                            GameObject doorWall = (GameObject)Instantiate(
                                gameScript.wallDoorPrefab,
                                location,
                                Quaternion.Euler(0, GetDirectionRotation((AdjacentDirections)requiredDirections[c]), 0));

                            doorWall.name = directionName + " Wall (1 Door)";
                            doorWall.transform.SetParent(newRoom.transform);

                            Destroy(newRoom.transform.Find(directionName + " Wall").gameObject);

                            GameObject trigger = (GameObject)Instantiate(
                                gameScript.roomTriggerPrefab,
                                triggerLocation,
                                Quaternion.Euler(0, GetDirectionRotation((AdjacentDirections)requiredDirections[c]), 0));

                            trigger.tag  = ((AdjacentDirections)requiredDirections[c]).ToString();
                            trigger.name = directionName + " Trigger";
                            trigger.transform.SetParent(newRoom.transform);
                        }
                    }


                    // Change invalid door walls to normal walls
                    for (int c = 0; c < invalidDirections.Count; c++)
                    {
                        if (gameScript.HasFlag(gameScript.GetRoomDirections(newRoom), (AdjacentDirections)invalidDirections[c]))
                        {
                            Vector3 location = newRoom.transform.position;
                            location.y = 3.75f;
                            string directionName = gameScript.GetNameOfDirection((AdjacentDirections)invalidDirections[c]);

                            if ((AdjacentDirections)invalidDirections[c] == AdjacentDirections.N)
                            {
                                location.z += 10;
                            }

                            else if ((AdjacentDirections)invalidDirections[c] == AdjacentDirections.E)
                            {
                                location.x += 10;
                            }

                            else if ((AdjacentDirections)invalidDirections[c] == AdjacentDirections.S)
                            {
                                location.z -= 10;
                            }

                            else if ((AdjacentDirections)invalidDirections[c] == AdjacentDirections.W)
                            {
                                location.x -= 10;
                            }

                            GameObject wall = (GameObject)Instantiate(
                                gameScript.wallPrefab,
                                location,
                                Quaternion.Euler(0, GetDirectionRotation((AdjacentDirections)invalidDirections[c]), 0));

                            wall.name = directionName + " Wall";
                            wall.transform.SetParent(newRoom.transform);

                            Destroy(newRoom.transform.Find(directionName + " Wall (1 Door)").gameObject);
                            Destroy(newRoom.transform.Find(directionName + " Trigger").gameObject);
                        }
                    }
                }
            }
        }
    }