void MakeDifficulties()
    {
        float lastDiff = dungeonLevel;
        float maxDiff  = 0;

        foreach (GameObject rm in rooms)
        {
            MapRoomController rmCntrl = rm.GetComponent <MapRoomController>();
            float             newDiff = 0;
            if (rmCntrl.coreRoom)
            {
                newDiff = lastDiff + Random.Range(0.05f, 0.25f);
                if (maxDiff < newDiff)
                {
                    maxDiff = newDiff;
                }
            }
            else // nerf extra rooms
            {
                newDiff = Random.Range(dungeonLevel, maxDiff);
            }
            rmCntrl.SetRoomDiffuculty(newDiff);
            lastDiff = newDiff;

            if (rmCntrl.roomIndex != 0)
            {
                rmCntrl.ShowRoom(false);
                rmCntrl.ShowPassages(false);
            }
        }
    }
    void MakePassages() // COMON LETS DO SOM PASAGES
    {
        rooms = new List <GameObject>(GameObject.FindGameObjectsWithTag("MapRoom"));

        List <GameObject> roomsTempList = new List <GameObject>(rooms);

        for (int i = roomsTempList.Count - 1; i > 0; i--)
        {
            MapRoomController roomController = roomsTempList[i].GetComponent <MapRoomController>();

            if (roomController.roomType != MapRoomController.Type.Secret)
            {
                RaycastHit2D hitLeft = Physics2D.Raycast(roomsTempList[i].transform.position, Vector2.left, 1.28f, 1 << 9);
                GeneratePass(roomsTempList, hitLeft, roomController, "Left", "Right");

                RaycastHit2D hitUp = Physics2D.Raycast(roomsTempList[i].transform.position, Vector2.up, 0.72f, 1 << 9);
                GeneratePass(roomsTempList, hitUp, roomController, "Up", "Down");

                RaycastHit2D hitRight = Physics2D.Raycast(roomsTempList[i].transform.position, Vector2.right, 1.28f, 1 << 9);
                GeneratePass(roomsTempList, hitRight, roomController, "Right", "Left");

                RaycastHit2D hitDown = Physics2D.Raycast(roomsTempList[i].transform.position, Vector2.down, 0.72f, 1 << 9);
                GeneratePass(roomsTempList, hitDown, roomController, "Down", "Up");
            }

            //REMOVE ROOM FROM LIST
            roomsTempList.RemoveAt(i);
        }
    }
Beispiel #3
0
    public void SetStartRoom(GameObject startRoom)
    {
        rooms = new List <GameObject>(GameObject.FindGameObjectsWithTag("MapRoom"));

        SetActiveRoom(startRoom);
        lastRoom = activeRoom;
    }
    void SetExtraRoomType(GameObject room, string roomType)
    {
        MapRoomController roomController = room.GetComponent <MapRoomController>();

        roomController.SetRoomType(roomType);
        roomController.SetCoreRoom(false);
    }
Beispiel #5
0
    public void ChangeRoom()
    {
        Destroy(activeRoom.chestInRoom); //remove chest
        activeRoom.chestInRoom = null;   //remove chest

        lastRoom = activeRoom;
        SetActiveRoom(newRoom.gameObject);
    }
    void SpawnStartRoom()
    {
        GameObject room = Instantiate(roomImage, transform.position, Quaternion.identity) as GameObject;

        room.name = "startRoom";
        room.transform.SetParent(transform);
        room.transform.localPosition = Vector3.zero;
        MapRoomController roomController = room.GetComponent <MapRoomController>();

        roomController.SetRoomType("Start");
        roomController.SetRoomIndex(0);
        roomController.SetCoreRoom(true);
        roomsPositions.Add(room.transform.position);
        roomsRemaining -= 1;
        rooms.Add(room);
    }
Beispiel #7
0
    void HitWall(MapRoomController room, string direction)
    {
        if (buttonCooldown <= 0)
        {
            buttonCooldown = 0.5f;
            GameManager.Instance.CameraShake(0.3f);
            if (room == null)
            {
                GameManager.Instance.HitWall(false);
            }
            else
            {
                switch (direction)
                {
                case "Left":
                    activeRoom.SetWallType("Left", MapRoomController.Wall.Passage);
                    room.SetWallType("Right", MapRoomController.Wall.Passage);
                    break;

                case "Up":
                    activeRoom.SetWallType("Up", MapRoomController.Wall.Passage);
                    room.SetWallType("Down", MapRoomController.Wall.Passage);
                    break;

                case "Right":
                    activeRoom.SetWallType("Right", MapRoomController.Wall.Passage);
                    room.SetWallType("Left", MapRoomController.Wall.Passage);
                    break;

                case "Down":
                    activeRoom.SetWallType("Down", MapRoomController.Wall.Passage);
                    room.SetWallType("Up", MapRoomController.Wall.Passage);
                    break;
                }
                GameManager.Instance.HitWall(true);
                activeRoom.UpdateNeighbours();
                SetButtonsTypes();
            }
        }
    }
Beispiel #8
0
    void GetRoomNeighbours(MapRoomController room)
    {
        RaycastHit2D hitL = Physics2D.Raycast(activeRoom.transform.position, Vector2.left, 1.28f, 1 << 9);

        if (hitL.collider != null)
        {
            if (hitL.collider.gameObject.tag == "MapRoom")
            {
                room.AddNeighbourLeft(hitL.collider.gameObject.GetComponent <MapRoomController>());
            }
        }
        RaycastHit2D hitU = Physics2D.Raycast(activeRoom.transform.position, Vector2.up, 0.72f, 1 << 9);

        if (hitU.collider != null)
        {
            if (hitU.collider.gameObject.tag == "MapRoom")
            {
                room.AddNeighbourUp(hitU.collider.gameObject.GetComponent <MapRoomController>());
            }
        }
        RaycastHit2D hitR = Physics2D.Raycast(activeRoom.transform.position, Vector2.right, 1.28f, 1 << 9);

        if (hitR.collider != null)
        {
            if (hitR.collider.gameObject.tag == "MapRoom")
            {
                room.AddNeighbourRight(hitR.collider.gameObject.GetComponent <MapRoomController>());
            }
        }
        RaycastHit2D hitD = Physics2D.Raycast(activeRoom.transform.position, Vector2.down, 0.72f, 1 << 9);

        if (hitD.collider != null)
        {
            if (hitD.collider.gameObject.tag == "MapRoom")
            {
                room.AddNeighbourDown(hitD.collider.gameObject.GetComponent <MapRoomController>());
            }
        }
    }
Beispiel #9
0
    void OpenDoor(MapRoomController room, string direction)
    {
        if (buttonCooldown <= 0)
        {
            buttonCooldown = 0.5f;
            if (GameManager.Instance.inventoryController.keys > 0)
            {
                switch (direction)
                {
                case "Left":
                    activeRoom.SetWallType("Left", MapRoomController.Wall.Passage);
                    room.SetWallType("Right", MapRoomController.Wall.Passage);
                    break;

                case "Up":
                    activeRoom.SetWallType("Up", MapRoomController.Wall.Passage);
                    room.SetWallType("Down", MapRoomController.Wall.Passage);
                    break;

                case "Right":
                    activeRoom.SetWallType("Right", MapRoomController.Wall.Passage);
                    room.SetWallType("Left", MapRoomController.Wall.Passage);
                    break;

                case "Down":
                    activeRoom.SetWallType("Down", MapRoomController.Wall.Passage);
                    room.SetWallType("Up", MapRoomController.Wall.Passage);
                    break;
                }
                GameManager.Instance.inventoryController.KeyLose();
                GameManager.Instance.PrintActionFeedback(null, "You used the key and opened the door.", null, false, true);
            }
            else
            {
                GameManager.Instance.PrintActionFeedback(null, "You have no keys!", null, false, true);
            }
            SetButtonsTypes();
        }
    }
Beispiel #10
0
    void SetActiveRoom(GameObject room)
    {
        MapRoomController roomController = room.GetComponent <MapRoomController>();

        foreach (GameObject _room in rooms)
        {
            MapRoomController _roomController = _room.GetComponent <MapRoomController>();
            _roomController.ActiveRoom(false);
            if (_roomController == roomController)
            {
                activeRoom = _roomController;
                _roomController.ActiveRoom(true);
            }
        }
        //set buttons types
        SetButtonsTypes();
        roomController.ShowRoom(true);
        roomController.ShowPassages(true);
        GetRoomNeighbours(roomController);
        roomController.UpdateNeighbours();

        activeRoom.SpawnChest();
    }
Beispiel #11
0
 public void AddNeighbourDown(MapRoomController room)
 {
     neighbourDown = room;
 }
Beispiel #12
0
 public void AddNeighbourRight(MapRoomController room)
 {
     neighbourRight = room;
 }
Beispiel #13
0
 public void AddNeighbourUp(MapRoomController room)
 {
     neighbourUp = room;
 }
    void GeneratePass(List <GameObject> roomsTempList, RaycastHit2D hit, MapRoomController roomController, string roomWall_1, string roomWall_2)
    {
        if (hit.collider != null && hit.collider.gameObject.tag == "MapRoom")
        {
            foreach (GameObject rm in roomsTempList)
            {
                if (rm == hit.collider.gameObject)
                {
                    MapRoomController neighbourRoomController = hit.collider.gameObject.GetComponent <MapRoomController>();

                    // TYPES //////////////////////////
                    if (roomController.roomType == MapRoomController.Type.Start)                                                                                  // START ROOM
                    {
                        if (neighbourRoomController.roomType == MapRoomController.Type.Default || neighbourRoomController.roomType == MapRoomController.Type.Npc) // DEFAULT OR NPC
                        {
                            if (neighbourRoomController.coreRoom)                                                                                                 // CORE ROOM
                            {
                                roomController.SetWallType(roomWall_1, MapRoomController.Wall.Passage);
                                neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.Passage);
                            }
                            else // NOT CORE ROOM
                            {
                                float random = Random.value;
                                if (random > 0.3f) //  passage
                                {
                                    roomController.SetWallType(roomWall_1, MapRoomController.Wall.Passage);
                                    neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.Passage);
                                }
                                else if (random > 0.6f) //  locker
                                {
                                    roomController.SetWallType(roomWall_1, MapRoomController.Wall.DoorLocked);
                                    neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.DoorLocked);
                                }
                                else //  SOLID WALL
                                {
                                    roomController.SetWallType(roomWall_1, MapRoomController.Wall.Solid);
                                    neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.Solid);
                                }
                            }
                        }
                        else if (neighbourRoomController.roomType == MapRoomController.Type.Secret || neighbourRoomController.roomType == MapRoomController.Type.Boss) // SECRET OR BOSS
                        {
                            roomController.SetWallType(roomWall_1, MapRoomController.Wall.Solid);
                            neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.Solid);
                        }
                        else if (neighbourRoomController.roomType == MapRoomController.Type.Treasure) // TREASURE
                        {
                            roomController.SetWallType(roomWall_1, MapRoomController.Wall.Solid);
                            neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.Solid);
                        }
                    }
                    else if (roomController.roomType == MapRoomController.Type.Boss)                    // BOSS ROOM
                    {
                        if (neighbourRoomController.roomIndex == 2 && neighbourRoomController.coreRoom) // BOSS ENTRANCE PASSAGE
                        {
                            roomController.SetWallType(roomWall_1, MapRoomController.Wall.Passage);
                            neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.Passage);
                        }
                        else // OTHER - SOLID WALL
                        {
                            roomController.SetWallType(roomWall_1, MapRoomController.Wall.Solid);
                            neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.Solid);
                        }
                    }
                    else if (roomController.roomType == MapRoomController.Type.Default || roomController.roomType == MapRoomController.Type.Npc) // DEFAULT OR NPC
                    {
                        if (neighbourRoomController.coreRoom)                                                                                    // CORE PASSAGE
                        {
                            int roomIndexesOdds = Mathf.Abs(neighbourRoomController.roomIndex - roomController.roomIndex);

                            if (roomIndexesOdds == 1 || neighbourRoomController.roomType == MapRoomController.Type.Start)
                            {
                                roomController.SetWallType(roomWall_1, MapRoomController.Wall.Passage);
                                neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.Passage);
                            }
                            else if (neighbourRoomController.roomType == MapRoomController.Type.Boss || roomIndexesOdds != 1)
                            {
                                if (neighbourRoomController.roomType != MapRoomController.Type.Start)
                                {
                                    roomController.SetWallType(roomWall_1, MapRoomController.Wall.Solid);
                                    neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.Solid);
                                }
                            }
                        }
                        else // OTHER
                        {
                            float random = Random.value;
                            if (random > 0.3f) //  passage
                            {
                                roomController.SetWallType(roomWall_1, MapRoomController.Wall.Passage);
                                neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.Passage);
                            }
                            else if (random > 0.6f) //  locker
                            {
                                roomController.SetWallType(roomWall_1, MapRoomController.Wall.DoorLocked);
                                neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.DoorLocked);
                            }
                            else //  SOLID WALL
                            {
                                roomController.SetWallType(roomWall_1, MapRoomController.Wall.Solid);
                                neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.Solid);
                            }
                        }
                    }
                    else if (roomController.roomType == MapRoomController.Type.Treasure) // TREASURE
                    {
                        if (neighbourRoomController.roomType == MapRoomController.Type.Boss)
                        {
                            roomController.SetWallType(roomWall_1, MapRoomController.Wall.Solid);
                            neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.Solid);
                        }
                        else
                        {
                            float random = Random.value;
                            if (random > 0.3f) // locker
                            {
                                roomController.SetWallType(roomWall_1, MapRoomController.Wall.DoorLocked);
                                neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.DoorLocked);
                            }
                            else // SOLID WALL
                            {
                                roomController.SetWallType(roomWall_1, MapRoomController.Wall.Solid);
                                neighbourRoomController.SetWallType(roomWall_2, MapRoomController.Wall.Solid);
                            }
                        }
                    }
                }
            }
        }
    }
    void SpawnMainRooms()
    {
        Vector3 lastRoomPosition = roomsPositions[0];

        Vector3   newRoomPosOffset = Vector3.zero;
        Direction lastDirection    = Direction.No;

        int repeats = 0;

        for (int i = roomsRemaining; i > 0; i--)
        {
            newDirection = new List <Direction>();

            switch (excludeDirecion)
            {
            case Direction.Left:
                newDirection.Add(Direction.Down);
                newDirection.Add(Direction.Right);
                newDirection.Add(Direction.Up);
                break;

            case Direction.Up:
                newDirection.Add(Direction.Down);
                newDirection.Add(Direction.Right);
                newDirection.Add(Direction.Left);
                break;

            case Direction.Right:
                newDirection.Add(Direction.Down);
                newDirection.Add(Direction.Left);
                newDirection.Add(Direction.Up);
                break;

            case Direction.Down:
                newDirection.Add(Direction.Left);
                newDirection.Add(Direction.Right);
                newDirection.Add(Direction.Up);
                break;
            }


            RaycastHit2D hitLeft = Physics2D.Raycast(lastRoomPosition, Vector2.left, 1.28f, 1 << 9);
            if (hitLeft.collider != null)
            {
                //                print(hitLeft.collider.name);
                if (hitLeft.collider.gameObject.tag == "MapRoom" && excludeDirecion != Direction.Left)
                {
                    newDirection.Remove(Direction.Left);
                }
            }

            RaycastHit2D hitUp = Physics2D.Raycast(lastRoomPosition, Vector2.up, 0.72f, 1 << 9);
            if (hitUp.collider != null)
            {
                //              print(hitUp.collider.name);
                if (hitUp.collider.gameObject.tag == "MapRoom" && excludeDirecion != Direction.Up)
                {
                    newDirection.Remove(Direction.Up);
                }
            }

            RaycastHit2D hitRight = Physics2D.Raycast(lastRoomPosition, Vector2.right, 1.28f, 1 << 9);
            if (hitRight.collider != null)
            {
                //               print(hitRight.collider.name);
                if (hitRight.collider.gameObject.tag == "MapRoom" && excludeDirecion != Direction.Right)
                {
                    newDirection.Remove(Direction.Right);
                }
            }

            RaycastHit2D hitDown = Physics2D.Raycast(lastRoomPosition, Vector2.down, 0.72f, 1 << 9);
            if (hitDown.collider != null)
            {
                //              print(hitDown.collider.name);
                if (hitDown.collider.gameObject.tag == "MapRoom" && excludeDirecion != Direction.Down)
                {
                    newDirection.Remove(Direction.Down);
                }
            }
            newDirection.Sort();
            //           print(newDirection.Count);

            int random = Random.Range(0, newDirection.Count);

            if (newDirection[random] == lastDirection)
            {
                if (repeats < maxRepeats)
                {
                    repeats += 1;
                }
                else
                {
                    switch (random)
                    {
                    case 0:
                        float localRandom0 = Random.value;
                        if (localRandom0 > 0.5f)
                        {
                            if (newDirection.Count > 1)
                            {
                                random = 1;
                            }
                        }
                        else if (newDirection.Count > 2)
                        {
                            random = 2;
                        }
                        break;

                    case 1:
                        float localRandom1 = Random.value;
                        if (localRandom1 > 0.5f)
                        {
                            random = 0;
                        }
                        else if (newDirection.Count > 2)
                        {
                            random = 2;
                        }
                        break;

                    case 2:
                        float localRandom2 = Random.value;
                        if (localRandom2 > 0.5f)
                        {
                            random = 0;
                        }
                        else if (newDirection.Count > 1)
                        {
                            random = 1;
                        }
                        break;
                    }
                    repeats = 0;
                }
            }
            else
            {
                repeats = 0;
            }

            switch (newDirection[random])
            {
            case Direction.Left:
                lastDirection    = Direction.Left;
                newRoomPosOffset = new Vector3(-1.28f, 0, 0);
                break;

            case Direction.Up:
                lastDirection    = Direction.Up;
                newRoomPosOffset = new Vector3(0, 0.72f, 0);
                break;

            case Direction.Right:
                lastDirection    = Direction.Right;
                newRoomPosOffset = new Vector3(1.28f, 0, 0);
                break;

            case Direction.Down:
                lastDirection    = Direction.Down;
                newRoomPosOffset = new Vector3(0, -0.72f, 0);
                break;
            }

            GameObject room = Instantiate(roomImage, lastRoomPosition, Quaternion.identity) as GameObject;

            if (i > 1)
            {
                room.name = "mainRoom_" + i;
                if (npcAmount < 2)
                {
                    float randomChance = Random.value; // NPC SPAWN CHANCE
                    if (randomChance > 0.75)
                    {
                        room.GetComponent <MapRoomController>().SetRoomType("Npc");
                        npcAmount += 1;
                    }
                    else
                    {
                        room.GetComponent <MapRoomController>().SetRoomType("Default");
                    }
                }
                else
                {
                    room.GetComponent <MapRoomController>().SetRoomType("Default");
                }
            }
            else
            {
                room.name = "mainRoom_1_bossRoom";
                room.GetComponent <MapRoomController>().SetRoomType("Boss");
            }
            room.transform.SetParent(transform);
            room.transform.localScale     = Vector3.one;
            room.transform.localPosition += newRoomPosOffset;
            MapRoomController roomController = room.GetComponent <MapRoomController>();
            roomController.SetRoomIndex(i);
            roomController.SetCoreRoom(true);
            roomsPositions.Add(room.transform.position);
            rooms.Add(room);


            lastRoomPosition = room.transform.position;
            roomsRemaining  -= 1;
        }
    }