예제 #1
0
        //update player, projectiles and current room
        //if the current room is defeated, then player can
        //move into the next rooms
        //if the next level needs to be generated, then do so
        //without resetting the player
        public void Update(float dt)
        {
            if (generateNextLevel)
            {
                //pass in false, don't reset player items and stats
                ResetDungeon(false);
                generateNextLevel = false;
            }

            player.Update(dt);
            ProjectileManager.Instance.Update(dt);

            if (Utility.Instance.IsKeyPressed(Keys.R))
            {
                ResetDungeon();
            }

            if (Utility.Instance.IsKeyPressed(Keys.T))
            {
                UncoverRooms();
            }

            m_CurrentRoom.Update(dt);

            if (m_CurrentRoom.Defeated)
            {
                //defeat trap room, then stats go back to normal
                if (m_CurrentRoom.GetRoomType == PreRoomType.TRAP)
                {
                    //saving of stats is done when player enters the trap room
                    player.ResetStatsToSaved();
                }

                #region Door collision checks
                if (m_CurrentRoom.CheckDoorCollidable(Direction.NORTH) && player.Intersects(m_CurrentRoom.GetDoorCollider(Direction.NORTH)))
                {
                    //check that connection is valid
                    int northOfCurrent = m_CurrentRoom.GetConnection(Direction.NORTH);
                    if (northOfCurrent != -1)
                    {
                        //get the next room
                        PreRoom nextRoom = m_PreRooms[northOfCurrent];

                        //make sure it is a valid room
                        if (nextRoom.GetRoomType != PreRoomType.NO_ROOM)
                        {
                            //move player to just above south door
                            player.Position = new Vector2(Utility.Instance.ScreenWidth * 0.5f, Utility.Instance.ScreenHeight - Door.height * 2.5f);

                            m_CurrentRoom = nextRoom;
                            m_PreRooms[northOfCurrent].Explored = true;
                            m_CurrentRoom.Initialise();
                            ProjectileManager.Instance.ClearBullets();
                        }
                    }
                }

                if (m_CurrentRoom.CheckDoorCollidable(Direction.SOUTH) && player.Intersects(m_CurrentRoom.GetDoorCollider(Direction.SOUTH)))
                {
                    int southOfCurrent = m_CurrentRoom.GetConnection(Direction.SOUTH);
                    if (southOfCurrent != -1)
                    {
                        PreRoom nextRoom = m_PreRooms[southOfCurrent];
                        if (nextRoom.GetRoomType != PreRoomType.NO_ROOM)
                        {
                            player.Position = new Vector2(Utility.Instance.ScreenWidth * 0.5f, Door.height * 1.5f);

                            m_CurrentRoom = nextRoom;
                            m_PreRooms[southOfCurrent].Explored = true;
                            m_CurrentRoom.Initialise();
                            ProjectileManager.Instance.ClearBullets();
                        }
                    }
                }

                if (m_CurrentRoom.CheckDoorCollidable(Direction.EAST) && player.Intersects(m_CurrentRoom.GetDoorCollider(Direction.EAST)))
                {
                    int eastOfCurrent = m_CurrentRoom.GetConnection(Direction.EAST);
                    if (eastOfCurrent != -1)
                    {
                        //east
                        PreRoom nextRoom = m_PreRooms[eastOfCurrent];
                        if (nextRoom.GetRoomType != PreRoomType.NO_ROOM)
                        {
                            //move player to just near west door
                            player.Position = new Vector2(Door.width * 1.5f, Utility.Instance.ScreenHeight * 0.5f);

                            m_CurrentRoom = nextRoom;
                            m_PreRooms[eastOfCurrent].Explored = true;
                            m_CurrentRoom.Initialise();
                            ProjectileManager.Instance.ClearBullets();
                        }
                    }
                }

                if (m_CurrentRoom.CheckDoorCollidable(Direction.WEST) && player.Intersects(m_CurrentRoom.GetDoorCollider(Direction.WEST)))
                {
                    int westOfCurrent = m_CurrentRoom.GetConnection(Direction.WEST);
                    if (westOfCurrent != -1)
                    {
                        //west
                        PreRoom nextRoom = m_PreRooms[westOfCurrent];
                        if (nextRoom.GetRoomType != PreRoomType.NO_ROOM)
                        {
                            //move player to just near east door
                            player.Position = new Vector2(Utility.Instance.ScreenWidth - Door.width * 2.5f, Utility.Instance.ScreenHeight * 0.5f);

                            m_CurrentRoom = nextRoom;
                            m_PreRooms[westOfCurrent].Explored = true;
                            m_CurrentRoom.Initialise();
                            ProjectileManager.Instance.ClearBullets();
                        }
                    }
                }
                #endregion
            }
        }
예제 #2
0
        //parameter checks for resetting the player
        public void ResetDungeon(bool reset = true)
        {
            if (reset)
            {
                player.Reset();
                ProjectileManager.Instance.ClearBullets();
            }

            //keep going if starting room is null
            //and there aren't enough rooms
            int counter = 0;
            int maxCounter = 100;

            while (counter < maxCounter)
            {
                //reset num filled rooms.
                //gets filled in when ProcedurallyFilledDungeon is called
                numFilledRooms = 0;
                counter++;

                //clear list, start from beginning
                m_PreRooms.Clear();

                //create rooms, add them to list
                CreatePreRooms();

                //traversal rooms
                //random start, random direction per step
                ProcedurallyFilledDungeon();

                RemoveAdjacentTreasureRooms();
                RemoveMultipleEntrances();

                //create specific classes for each room type
                SpecialisePreRooms();

                //make sure adj rooms are connected properly
                LinkAdjacentRooms();

                //make sure player can move from one room to the next
                MakeDoorsCollidable();

                //set the current room to be the starting room
                m_CurrentRoom = StartRoom;

                if (BossRoom != null && StartRoom != null && EndRoom != null && numFilledRooms > m_MinRooms && numFilledRooms < m_MaxRooms)
                {
                    m_CurrentRoom.Explored = true;
                    ProjectileManager.Instance.ClearBullets();
                    Console.WriteLine(counter.ToString() + " tries for success.");
                    break;
                }
            }
        }