Example #1
0
    public DungeonRoom GetRoomInDirection(DungeonRoom fromRoom, Direction direction)
    {
        Vector2 toRoomLocation = fromRoom.roomCoordinates;

        switch (direction)
        {
            case Direction.East:
                toRoomLocation.x++;
                break;
            case Direction.West:
                toRoomLocation.x--;
                break;
            case Direction.North:
                toRoomLocation.y++;
                break;
            case Direction.South:
                toRoomLocation.y--;
                break;
            default:
                break;
        }

        DungeonRoom toRoom = GetRoom(toRoomLocation);

        return toRoom;
    }
Example #2
0
 /*
  * METHODS
  */
 // Clean QuadTree
 public void Clear()
 {
     seed = -1;
     boundary = new AABB();
     northWest = null;
     northEast = null;
     southWest = null;
     southEast = null;
     room = null;
 }
Example #3
0
    public void MoveToRoom(DungeonRoom room, bool spawnMonsters)
    {
        currentRoom = room;

        SpawnerManager spawnManager = room.GetComponent<SpawnerManager>();

        if (spawnManager != null)
        {
            if (spawnMonsters)
            {
                spawnManager.SelectAndSpawnMonsters();
            }
            else
            {
                spawnManager.monstersSpawned = true; //flag so this room doesn't spawn monsters later
            }
        }
    }
Example #4
0
        private void AddHallways(AreaMap.Tile[] tiles, DungeonRoom[] allRooms, List <DungeonRoom> mainRoomGraph, out List <Vector2> doorLocations)
        {
            doorLocations = new List <Vector2>();

            for (int i = 0; i < mainRoomGraph.Count; i++)
            {
                DungeonRoom mainRoom = mainRoomGraph[i];

                DigOutRoom(tiles, mainRoom);

                // and check all of this rooms connections to create hallways
                for (int j = 0; j < mainRoom.neighbors.Count; j++)
                {
                    DungeonRoom neighborRoom = mainRoom.neighbors[j];

                    // add a doorway for this hallway
                    //doorLocations.Add(DoorLocation(mainRoom, neighborRoom));

                    DigOutHallway(tiles, mainRoom, neighborRoom, allRooms, doorLocations);
                }
            }
        }
    private Direction CheckDirection(DungeonRoom other)
    {
        Vector2 dir = cellPos - other.cellPos;

        if (Mathf.Abs(dir.x) > Mathf.Abs(dir.y))        //X軸の変化量がY軸より大きい場合
        {
            if (dir.x > 0)                              //自分のXが相手のXより大きい場合
            {
                return(Direction.Xplus);
            }
            else
            {
                return(Direction.Xminus);
            }
        }

        if (dir.y > 0)                                  //自分のZが相手のZより大きい場合
        {
            return(Direction.Zplus);
        }
        return(Direction.Zminus);
    }
Example #6
0
    public void SetData(DungeonRoom roomInfo, Action <RoomPosition> callback)
    {
        _info      = roomInfo;
        _callback  = callback;
        _roomImage = GetComponent <Image>();

        switch (_info.Content)
        {
        case RoomContent.None:
            roomHint.text = "You hear nothing!";
            break;

        case RoomContent.Battle:
            roomHint.text = "Sounds of Metal";
            break;

        case RoomContent.Obstacle:
            roomHint.text = "The Path is blocked";
            break;

        case RoomContent.Trap:
            roomHint.text = "This seems unsafe";
            break;

        case RoomContent.Generic:
            roomHint.text = "What could be here?";
            break;

        case RoomContent.Gift:
            roomHint.text = "Loot! Loot! Loot!";
            break;

        case RoomContent.Start:
            break;

        case RoomContent.Boss:
            break;
        }
    }
Example #7
0
    public void AttachAstar(DungeonRoom room)
    {
        AStarGrid.transform.parent   = room.gameObject.transform;
        AStarGrid.transform.position = room.gameObject.transform.position;
        AStarGrid.collidableMap      = room.GetComponent <Tilemap>();

        //AStarGrid.collidableMap = room.gameObject.transform.Find("Pattern").GetComponent<Tilemap>();

        //collidableMap = DungeonManager.Instance.GetCurrentDungeonRoom()
        //    .transform.Find("Pattern").GetComponent<Tilemap>();

        //AstarData  data = AstarPath.active.data;
        //GridGraph gridGraph = data.gridGraph;
        // gridGraph.width = 80;
        // gridGraph.depth = 60;
        //gridGraph.SetDimensions(80, 60, 1f);
        //gridGraph.center = room.gameObject.transform.position;
        //gridGraph.Scan();
        // Debug.Log(gridGraph.center);

        // Debug.Log(gridGraph.center);
    }
Example #8
0
    public static void LoadFromText(string fileName, DungeonRoom room)
    {
        // THese are used to parse the data from the text file
        string path = "Assets/Levels/" + fileName;

        string[] split;
        string[] vector;
        string[] size;

        StreamReader reader = new StreamReader(path);

        string line;

        while ((line = reader.ReadLine()) != null)
        {
            // if (line == "Walls")
            // {
            //     while ((line = reader.ReadLine()) != "Cubes")
            //     {
            //         line = line.Replace("(", string.Empty);
            //         line = line.Replace(")", string.Empty);
            //         split = line.Split(':');
            //         // Holds the x y z values of the position vector for the wall
            //         vector = split[0].Split(',');
            //         // Holds the size width/height for the walls spriteRenderer
            //         size = split[1].Split(',');
            //
            //         // Adds this instantiation to the ObjectManagers walls list
            //         DungeonRoom.AddWall(
            //             new Vector3(float.Parse(vector[0]), float.Parse(vector[1]), float.Parse(vector[2])),
            //             float.Parse(size[0]), float.Parse(size[1]));
            //     }
            // }

            // Get the center position of the room to create the walls.
        }

        reader.Close();
    }
    private void GenerateRoom(int roomX, int roomY, int roomWidth, int roomHeight) /////Generates rooms in tiles[]
    {
        DungeonRoom newRoom = new DungeonRoom(roomWidth, roomHeight);

        newRoom.xPos     = roomX;
        newRoom.yPos     = roomY;
        newRoom.roomType = roomTypes[rooms.Count];

        for (int x = 0; x < roomWidth; x++)
        {
            for (int y = 0; y < roomHeight; y++)
            {
                if (x + roomX < gridSize && y + roomY < gridSize)
                {
                    tiles[x + roomX, y + roomY] = Tile.FLOOR;
                    newRoom.roomTiles[x, y]     = Tile.FLOOR;
                }
            }
        }

        rooms.Add(newRoom);
    }
Example #10
0
    /// <summary>
    /// Change une <see cref="DungeonRoom"/> d'un KeyLevel à un autre
    /// </summary>
    /// <param name="roomToUpdate">La pièce à update</param>
    /// <param name="newKeyLevel">Le nouveau niveau de la pièece</param>
    private void ChangeKeyLevel(DungeonRoom roomToUpdate, int newKeyLevel)
    {
        int oldKeyLevel = roomToUpdate.GetKeyLevel();

        if (oldKeyLevel != newKeyLevel)
        {
            if (!roomPerKeyLevel.ContainsKey(oldKeyLevel))
            {
                throw new System.Exception("Erreur avec le vieux niveau de clé");
            }

            DungeonRoom roomToDelete = roomPerKeyLevel[oldKeyLevel].FirstOrDefault(r => r.GetRoomType() == RoomType.BOSS);
            roomPerKeyLevel[oldKeyLevel].Remove(roomToDelete);

            roomToUpdate.SetKeyLevel(currentKeyLevel);
            if (!roomPerKeyLevel.ContainsKey(currentKeyLevel))
            {
                throw new System.Exception("Erreur avec le nouveau niveau de clé");
            }

            roomPerKeyLevel[newKeyLevel].Add(roomToUpdate);
        }
    }
Example #11
0
    public bool IsRoomSurounded(DungeonRoom room)
    {
        bool surroundedByRooms = true;

        foreach (var dir in DirectionUtility.GetDirections())
        {
            if (GetRoomInDirection(room, dir) == null)
            {
                surroundedByRooms = false;
            }
        }

        bool onEdge = false;
        var  coord  = room.Coordinate;

        if (Mathf.Abs(coord.x) >= MaxXCoord ||
            Mathf.Abs(coord.y) >= MaxYCoord)
        {
            onEdge = true;
        }

        return(surroundedByRooms || onEdge);
    }
    protected Tile GetFreeTileOnRoom(DungeonRoom room, int radius = 0)
    {
        // get a random free tile inside the given room
        int c = 0;

        while (true)
        {
            DungeonTile dtile = room.tiles[Random.Range(0, room.tiles.Count)];
            Tile        tile  = grid.GetTile(dtile.x, dtile.y);
            if (tile != null && TileIsFree(tile, radius))
            {
                return(tile);
            }

            c++; if (c == 1000)
            {
                break;
            }
        }

        //Debug.LogWarning ("No free tile available in room " + room.id + ". Escaping...");
        return(null);
    }
Example #13
0
    public void AssignWallMaterials(DungeonRoom dr)
    {
        DungeonRoomInfo info = dr.Info;

        // Set wall materials according to walltype
        dr.wall_N.GetComponent <Renderer>().material = GetWallMaterial(DungeonRoomInfo.WallDirection.North, info.northWallType);
        dr.wall_E.GetComponent <Renderer>().material = GetWallMaterial(DungeonRoomInfo.WallDirection.East, info.eastWallType);
        dr.wall_S.GetComponent <Renderer>().material = GetWallMaterial(DungeonRoomInfo.WallDirection.South, info.southWallType);
        dr.wall_W.GetComponent <Renderer>().material = GetWallMaterial(DungeonRoomInfo.WallDirection.West, info.westWallType);

        dr.wall_N2.GetComponent <Renderer>().material = GetWallMaterial(DungeonRoomInfo.WallDirection.North, DungeonRoomInfo.WallType.Top);
        dr.wall_E2.GetComponent <Renderer>().material = GetWallMaterial(DungeonRoomInfo.WallDirection.East, DungeonRoomInfo.WallType.Top);
        dr.wall_S2.GetComponent <Renderer>().material = GetWallMaterial(DungeonRoomInfo.WallDirection.South, DungeonRoomInfo.WallType.Top);
        dr.wall_W2.GetComponent <Renderer>().material = GetWallMaterial(DungeonRoomInfo.WallDirection.West, DungeonRoomInfo.WallType.Top);

        if (info.floorMaterial == null)
        {
            info.floorMaterial = new Material(defaultFloor);
        }

        dr.floor.GetComponent <Renderer>().material   = info.floorMaterial;
        dr.ceiling.GetComponent <Renderer>().material = defaultFloor;
    }
Example #14
0
        public static ActionArgs GetActionArgs(PlayerCharacter sender, string toParse)
        {
            toParse = toParse.ToLower();
            MudCharacter target    = null;
            string       arguments = null;

            string[] words = toParse.Split(' ');
            if (words.Length > 2)
            {
                return(null);
            }
            DungeonRoom room = sender.Room;

            MudCharacter[] characters = room.GetCharactersInRoom();
            foreach (string word in words)
            {
                if (target != null && arguments == null)
                {
                    arguments = word;
                    break;
                }
                int targetNum;
                if (int.TryParse(word, out targetNum))
                {
                    if (targetNum >= sender.Roomates.Length)
                    {
                        sender.NotifyPlayer("not a valid target");
                        return(null);
                    }
                    target = sender.Roomates[targetNum];
                    continue;
                }

                arguments = word;
            }
            return(new ActionArgs(sender, target, arguments));
        }
    public void Hit(DungeonRoom other)
    {
        Direction direction = CheckDirection(other);                    //他の部屋のどの方向

        //一マスずつ修正
        switch (direction)
        {
        case Direction.Xplus:
            cellPos.x += 1;
            break;

        case Direction.Xminus:
            cellPos.x -= 1;
            break;

        case Direction.Zplus:
            cellPos.y += 1;
            break;

        case Direction.Zminus:
            cellPos.y -= 1;
            break;
        }
    }
Example #16
0
    public DungeonRoom AddRoom(int x, int y, int sizeX, int sizeY)
    {
        if (!CheckValidBounds(x, y, sizeX, sizeY))
        {
            throw new ArgumentException("Invalid room bounds (outside dungeon)");
        }

        if (!CheckSpaceType(x, y, sizeX, sizeY, DungeonTileType.Wall))
        {
            throw new ArgumentException("Invalid room bounds (can't replace non-wall tiles)");
        }

        DungeonRoom room = new DungeonRoom(this, x, y, sizeX, sizeY);

        rooms.Add(room);

        DungeonTile roomTile = DungeonTile.EmptyTile;

        roomTile.type = DungeonTileType.Room;

        SetTile(x, y, sizeX, sizeY, roomTile);

        return(room);
    }
Example #17
0
    public void RespawnAllEnemies(DungeonRoom room)
    {
        room.isRespawned = true;
        if (!room.isRespawnable)
        {
            return;
        }

        int baseIndex = 0;

        for (int i = 0; i < room.monster.Count; i++)
        {
            for (int j = 0; j < room.monster[i].size; j++)
            {
                MonsterDungeon instance = null;
                switch (room.monster[i].tier)
                {
                case Tier.TierOne:
                    instance = tierOne[Random.Range(0, tierOne.Count)];
                    MonsterPoolManager.Instance.ReuseObject(Tier.TierOne, instance.monster, room.respwanPoint[baseIndex + j].position, room.respwanPoint[baseIndex + j].rotation);
                    break;

                case Tier.TierTwo:
                    instance = tierTwo[Random.Range(0, tierTwo.Count)];
                    MonsterPoolManager.Instance.ReuseObject(Tier.TierTwo, instance.monster, room.respwanPoint[baseIndex + j].position, room.respwanPoint[baseIndex + j].rotation);
                    break;

                case Tier.TierThree:
                    instance = tierThree[Random.Range(0, tierThree.Count)];
                    MonsterPoolManager.Instance.ReuseObject(Tier.TierThree, instance.monster, room.respwanPoint[baseIndex + j].position, room.respwanPoint[baseIndex + j].rotation);
                    break;
                }
            }
            baseIndex += room.monster[i].size;
        }
    }
    public PlanetData Generate(float difficultySetting)
    {
        PlanetData data = new PlanetData();
        PlanetDifficultyModifiers difficultyModifiers
            = new PlanetDifficultyModifiers(difficultySetting);

        DungeonRoom currentRoom = null;
        int         keyLevel    = 1;

        //rule 1 -	Create starter room
        DungeonRoom startRoom = new StartRoom(IntPair.zero, null);

        data.AddRoom(startRoom);
        data.startRoom = startRoom;

        //rule 2 -	"Current Room" is starter room
        currentRoom = data.startRoom;

        //rule 7 -	Repeat steps 3 - 6 Y amount of times.
        int branchCount = Mathf.Max(1, Random.Range(
                                        difficultyModifiers.minBranchCount,
                                        PlanetDifficultyModifiers.MAX_BRANCH_COUNT));

        for (int j = 0; j < branchCount; j++)
        {
            //rule 3 -	Create a single branch from the "Current room" until X rooms have been
            //			created. Branch can't overlap with existing rooms. If branch meets a dead
            //			end, end the branch.
            int branchLength = Mathf.Max(1,
                                         Random.Range(difficultyModifiers.minBranchLength, difficultyModifiers.maxBranchLength));
            for (int i = 0; i < branchLength; i++)
            {
                DungeonRoom newRoom = CreateRandomExit(data, currentRoom, false,
                                                       keyLevel, false, false, difficultyModifiers);
                if (newRoom == currentRoom)
                {
                    break;
                }
                currentRoom = newRoom;
            }

            //rule 4 -	Place a key at the end of that branch
            currentRoom.AddKey(keyLevel);

            //rule 5 -	Create a locked exit to a new room from any existing room except the end of
            //			that branch.
            List <DungeonRoom> existingRooms = data.GetRooms();
            DungeonRoom        lockRoom      = currentRoom;
            do
            {
                int randomIndex = Random.Range(0, existingRooms.Count);
                lockRoom = existingRooms[randomIndex];
            } while (lockRoom == currentRoom || lockRoom.ExitCount == 4);
            lockRoom = CreateRandomExit(data, lockRoom, true,
                                        keyLevel, j == branchCount - 1, false, difficultyModifiers);
            keyLevel++;

            //rule 6 -	"Current room" is the new room on the other side of the locked exit
            currentRoom = lockRoom;
        }

        //rule 8 -	"Current room" is the final room
        data.finalRoom = currentRoom;

        //rule 9 -	Create "Dead end" branches Z times of X length from any room except the boss
        //			room.
        branchCount = Mathf.Max(0, Random.Range(difficultyModifiers.minDeadEndCount, difficultyModifiers.maxDeadEndCount));
        for (int i = 0; i < branchCount; i++)
        {
            List <DungeonRoom> existingRooms = data.GetRooms();
            DungeonRoom        deadEndStart  = null;
            do
            {
                int randomIndex = Random.Range(0, existingRooms.Count);
                deadEndStart = existingRooms[randomIndex];
            } while (deadEndStart == data.finalRoom || deadEndStart.ExitCount == 4);
            currentRoom = deadEndStart;

            int branchLength = Mathf.Max(1,
                                         Random.Range(difficultyModifiers.minBranchLength, difficultyModifiers.maxBranchLength));
            for (int j = 0; j < branchLength; j++)
            {
                DungeonRoom newRoom = CreateRandomExit(data, currentRoom, false,
                                                       keyLevel, false, j == branchLength - 1, difficultyModifiers);
                if (newRoom == currentRoom)
                {
                    break;
                }
                currentRoom = newRoom;
            }
        }

        for (int i = 0; i < data.GetRoomCount(); i++)
        {
            data.GetRooms()[i].GenerateContent();
        }

        for (int i = 0; i < data.GetRoomCount(); i++)
        {
            data.GetRooms()[i].GenerateOuterWalls();
        }

        return(data);
    }
 public bool Connects(DungeonRoom roomOne, DungeonRoom roomTwo)
 {
     return((RoomA == roomOne && RoomB == roomTwo) || (RoomB == roomOne && RoomA == roomTwo));
 }
    private void CreateFloor()
    {
        //The location for the next section of the dungeon floor to be created at
        Vector3 SpawnLocation = new Vector3(0, 0, 0);
        //The room number that is being added next
        int NextRoomNumber = 0;
        //The dimensions/size of a section of the dungeon floor
        Vector2 FloorSectionDimensions = new Vector2(0, 0);
        FloorSectionDimensions.x = DungeonFloor1x1Prefab.GetComponent<MeshFilter>().sharedMesh.bounds.size.x;
        FloorSectionDimensions.y = DungeonFloor1x1Prefab.GetComponent<MeshFilter>().sharedMesh.bounds.size.z;

        //Loop through the length and width of the room to instantiate each room
        for ( int i = 0; i < DungeonSize.x; i++ )
        {
            for ( int j = 0; j < DungeonSize.y; j++ )
            {
                //Create a room object to hold all the objects in the room
                DungeonRoom NewRoom = new DungeonRoom();
                //Give the room its number
                NewRoom.RoomNumber = NextRoomNumber;
                NextRoomNumber++;
                //Give the room its position in the grid
                NewRoom.RoomPosition = new Vector2(i, j);
                //Instantiate the floor of the new room
                NewRoom.DungeonFloor = (GameObject) Instantiate(DungeonFloor1x1Prefab, SpawnLocation, Quaternion.identity);
                //Set the floor as a child of the dungeon root object
                NewRoom.DungeonFloor.transform.parent = DungeonRoot.transform;
                //Add the new room to our list of all dungeon rooms
                DungeonRooms.Add(NewRoom);
                //Offset the x position for spawning the next floor section
                SpawnLocation.x += FloorSectionDimensions.x;
            }
            //Offset the z position and reset the x pos for spawning the next floor section
            SpawnLocation.x = 0;
            SpawnLocation.z += FloorSectionDimensions.y;
        }
    }
 private void LockVertically(DungeonRoom lower, DungeonRoom upper, int lockID)
 {
     ConnectVertically(lower, upper);
     lower.Lock(Direction.Up, lockID);
     upper.Lock(Direction.Down, lockID);
 }
    GameObject getRoomTriforce(Vector3 pos)
    {
        GameObject drHolder = new GameObject("RoomTriforce");
        drHolder.transform.position = pos;
        drHolder.transform.parent = roomHolder.transform;

        DungeonRoom dr = new DungeonRoom();
        dr.room = Instantiate(roomG, pos, Quaternion.identity) as GameObject;
        dr.room.transform.parent = drHolder.transform;

        GameObject objHolder = new GameObject("Objs");
        objHolder.transform.position = pos;
        objHolder.transform.parent = drHolder.transform;

        const int NUM_OBJS = 1;
        dr.objs = new GameObject[NUM_OBJS];

        dr.objs[0] = Instantiate(triforce, new Vector3(0, -1, 0), Quaternion.identity) as GameObject;

        // TODO: blocks around triforce

        for(int i=0; i < NUM_OBJS; ++i){
            dr.objs[i].GetComponent<SpriteRenderer>().sortingOrder = 2;
            dr.objs[i].transform.parent = objHolder.transform;
        }

        return drHolder;
    }
 public void CreateRoom()
 {
     rooms.Add(i.ToString(), DungeonRoom.MakeRoom(wallPrefab));
     i++;
 }
    //Uses A* pathfinding to create a path to the target room
    //so it can be reached by the player
    private void PathToRoomAStar(DungeonRoom TargetRoom)
    {
        //Layout of this A* pathfinder inspired by the tutorial at
        //http://www.raywenderlich.com/4946/introduction-to-a-pathfinding

        //The start and end nodes of the path
        DungeonRoom StartRoom = GetClosestRoom(TargetRoom, false);
        DungeonRoom EndRoom = TargetRoom;

        //Dungeon Lists
        List<DungeonRoom> OpenList = new List<DungeonRoom>();   //Rooms being considered to find the shortest path
        List<DungeonRoom> ClosedList = new List<DungeonRoom>();    //Rooms that will no longer be considered
        List<DungeonRoom> CameFrom = new List<DungeonRoom>();   //The path to follow

        //We begin by adding the start room to the open list
        OpenList.Add(StartRoom);
        //Set the start nodes G Score to 0
        StartRoom.GScore = 0;
        //Set the start nodes F Score
        StartRoom.FScore = StartRoom.GScore + CalculateHScore(StartRoom, EndRoom);

        //Loop through the open set until its empty
        while (OpenList.Count > 0)
        {
            //Find the node in OpenSet which has the lowest
            //F Score value
            DungeonRoom Current = GetLowestFScore(OpenList);

            //If the Current room is the Target room, then the pathway
            //has been completed
            if (Current == EndRoom)
            {
                ReconstructPath(StartRoom, EndRoom);
                return;
            }

            //Move the Current room from the open set to the closed set
            OpenList.Remove(Current);
            ClosedList.Add(Current);

            //Find the neighbouring rooms of the Current room
            List<DungeonRoom> CurrentNeighbours = new List<DungeonRoom>();
            AddAdjacentRooms(Current, CurrentNeighbours);

            //Loop through the Current neighbouring rooms
            for ( int i = 0; i < CurrentNeighbours.Count; i++ )
            {
                //Get the neighbour room we are checking
                DungeonRoom Neighbour = CurrentNeighbours[i];

                //If the neighbour room is in the closed list, ignore it
                if (ClosedList.Contains(Neighbour))
                    continue;
                //Length of this path
                int TentativeGScore = Current.GScore + (int)(Vector3.Distance(Current.DungeonFloor.transform.position, Neighbour.DungeonFloor.transform.position));
                //Discover a new node
                if (!OpenList.Contains(Neighbour))
                    OpenList.Add(Neighbour);
                else if (TentativeGScore >= Current.GScore)
                    continue; //This is not a better path

                //This path is the best until now, record it!
                Neighbour.ParentRoom = Current;
                Neighbour.GScore = TentativeGScore;
                Neighbour.FScore = Neighbour.GScore + CalculateHScore(Neighbour, EndRoom);
            }
        }
    }
Example #25
0
 /// <summary>
 /// Reset the dungeon room array with the new number of dungeon rooms.
 /// </summary>
 /// <param name="numberOfRooms">The new number of dungeon rooms.</param>
 public void ResetRooms(int numberOfRooms)
 {
     Rooms = new DungeonRoom[numberOfRooms];
 }
 private bool IsRoomAdjacent(DungeonRoom StartRoom, DungeonRoom TargetRoom)
 {
     //Find the 4 positions the 4 adjacent rooms would be in
     Vector2 NorthPos = new Vector2(StartRoom.RoomPosition.x, StartRoom.RoomPosition.y + 1);
     Vector2 EastPos = new Vector2(StartRoom.RoomPosition.x + 1, StartRoom.RoomPosition.y);
     Vector2 SouthPos = new Vector2(StartRoom.RoomPosition.x, StartRoom.RoomPosition.y - 1);
     Vector2 WestPos = new Vector2(StartRoom.RoomPosition.x - 1, StartRoom.RoomPosition.y);
     //Check if these room positions are within the bounds of the dungeon size
     bool NorthPosValid =    NorthPos.x >= DungeonSize.x ||
                             NorthPos.y >= DungeonSize.y ||
                             NorthPos.x < 0 ||
                             NorthPos.y < 0
                             ? false : true;
     bool EastPosValid =     EastPos.x >= DungeonSize.x ||
                             EastPos.y >= DungeonSize.y ||
                             EastPos.x < 0 ||
                             EastPos.y < 0
                             ? false : true;
     bool SouthPosValid =    SouthPos.x >= DungeonSize.x ||
                             SouthPos.y >= DungeonSize.y  ||
                             SouthPos.x < 0 ||
                             SouthPos.y < 0
                             ? false : true;
     bool WestPosValid =     WestPos.x >= DungeonSize.x ||
                             WestPos.y >= DungeonSize.y ||
                             WestPos.x < 0 ||
                             WestPos.y < 0
                             ? false : true;
     /*
     //Print if these room positions are valid
     print("North Valid: " + NorthPosValid);
     print("East Valid: " + EastPosValid);
     print("South Valid: " + SouthPosValid);
     print("West Valid: " + WestPosValid);
     */
     //Get the 4 adjacent dungeon rooms if they are valid
     DungeonRoom NorthRoom = NorthPosValid ? GetNorthRoom(StartRoom) : null;
     DungeonRoom EastRoom = EastPosValid ? GetEastRoom(StartRoom) : null;
     DungeonRoom SouthRoom = SouthPosValid ? GetSouthRoom(StartRoom) : null;
     DungeonRoom WestRoom = WestPosValid ? GetWestRoom(StartRoom) : null;
     //Check each room to see if any are the target room
     if (NorthPosValid && NorthRoom.DungeonFloor.transform.position == TargetRoom.DungeonFloor.transform.position)
         return true;
     if (EastPosValid && EastRoom.DungeonFloor.transform.position == TargetRoom.DungeonFloor.transform.position)
         return true;
     if (SouthPosValid && SouthRoom.DungeonFloor.transform.position == TargetRoom.DungeonFloor.transform.position)
         return true;
     if (WestPosValid && WestRoom.DungeonFloor.transform.position == TargetRoom.DungeonFloor.transform.position)
         return true;
     //We have check each adjacent room, and found that none of them are the
     //room that we are checking for
     return false;
 }
    //Creates a path to the target room so it can be reached
    //by the player
    private void PathToRoom(DungeonRoom TargetRoom, bool UseAStar)
    {
        //If we are going to use A*, pass the job onto another function
        if (UseAStar)
        {
            PathToRoomAStar(TargetRoom);
            return;
        }

        //Find the room we will start the path from, this will be the
        //closest non boss, non void type room to the target room
        DungeonRoom CurrentRoom = GetClosestRoom(TargetRoom, false);

        bool PathComplete = false;

        while (!PathComplete)
        {
            //If the current room is adjacent to the target room then the path has been completed
            if (IsRoomAdjacent(CurrentRoom, TargetRoom))
            {
                PathComplete = true;
                return;
            }

            //Get the positions the 4 adjacent rooms would be in
            Vector2 NorthPos = new Vector2(CurrentRoom.RoomPosition.x, CurrentRoom.RoomPosition.y + 1);
            Vector2 EastPos = new Vector2(CurrentRoom.RoomPosition.x + 1, CurrentRoom.RoomPosition.y);
            Vector2 SouthPos = new Vector2(CurrentRoom.RoomPosition.x, CurrentRoom.RoomPosition.y - 1);
            Vector2 WestPos = new Vector2(CurrentRoom.RoomPosition.x - 1, CurrentRoom.RoomPosition.y);

            //Check if these room positions are within the bounds of the dungeon size
            bool NorthPosValid = NorthPos.x >= DungeonSize.x ||
                                 NorthPos.y >= DungeonSize.y ||
                                 NorthPos.x < 0 ||
                                 NorthPos.y < 0
                                 ? false : true;
            bool EastPosValid = EastPos.x >= DungeonSize.x ||
                                EastPos.y >= DungeonSize.y ||
                                EastPos.x < 0 ||
                                EastPos.y < 0
                                ? false : true;
            bool SouthPosValid = SouthPos.x >= DungeonSize.x ||
                                 SouthPos.y >= DungeonSize.y ||
                                 SouthPos.x < 0 ||
                                 SouthPos.y < 0
                                 ? false : true;
            bool WestPosValid = WestPos.x >= DungeonSize.x ||
                                WestPos.y >= DungeonSize.y ||
                                WestPos.x < 0 ||
                                WestPos.y < 0
                                ? false : true;

            //Get the four adjacent rooms if they are valid
            DungeonRoom NorthRoom = NorthPosValid ? GetNorthRoom(CurrentRoom) : null;
            DungeonRoom EastRoom = EastPosValid ? GetEastRoom(CurrentRoom) : null;
            DungeonRoom SouthRoom = SouthPosValid ? GetSouthRoom(CurrentRoom) : null;
            DungeonRoom WestRoom = WestPosValid ? GetWestRoom(CurrentRoom) : null;

            //Calculate the distance from each of these adjacent rooms to the target room, if they are valid
            float NorthDistance = NorthPosValid ? Vector3.Distance(NorthRoom.DungeonFloor.transform.position, TargetRoom.DungeonFloor.transform.position) : -1;
            float EastDistance = EastPosValid ? Vector3.Distance(EastRoom.DungeonFloor.transform.position, TargetRoom.DungeonFloor.transform.position) : -1;
            float SouthDistance = SouthPosValid ? Vector3.Distance(SouthRoom.DungeonFloor.transform.position, TargetRoom.DungeonFloor.transform.position) : -1;
            float WestDistance = WestPosValid ? Vector3.Distance(WestRoom.DungeonFloor.transform.position, TargetRoom.DungeonFloor.transform.position) : -1;

            //Find which of these, which isnt a boss room, is a valid room and is closest to the CurrentRoom
            DungeonRoom ClosestRoom = null;
            float ClosestDistance = 0.0f;
            if (NorthPosValid && NorthRoom.RoomType != RoomTypes.BossRoom)
            {
                ClosestRoom = NorthRoom;
                ClosestDistance = NorthDistance;
            }
            if (EastPosValid && EastRoom.RoomType != RoomTypes.BossRoom)
            {
                //If closest distance still equals 0, then north room was the boss room
                //Otherwise, check if this room is closer
                if (ClosestDistance == 0.0f || EastDistance < ClosestDistance)
                {
                    ClosestRoom = EastRoom;
                    ClosestDistance = EastDistance;
                }
            }
            if (SouthPosValid && SouthRoom.RoomType != RoomTypes.BossRoom)
            {
                if (SouthDistance < ClosestDistance)
                {
                    ClosestRoom = SouthRoom;
                    ClosestDistance = SouthDistance;
                }
            }
            if (WestPosValid && WestRoom.RoomType != RoomTypes.BossRoom)
            {
                if (WestDistance < ClosestDistance)
                {
                    ClosestRoom = WestRoom;
                    ClosestDistance = WestDistance;
                }
            }

            //Now we know the first step on our path toward the TargetRoom
            CurrentRoom = ClosestRoom;
            //If this room is a void room, change it to a path room
            if (CurrentRoom.RoomType == RoomTypes.VoidRoom)
                SetToPathRoom(ClosestRoom);
        }
    }
 private DungeonRoom GetWestRoom(DungeonRoom StartRoom)
 {
     //Get the position of the north room
     Vector2 WestPosition = new Vector2(StartRoom.RoomPosition.x - 1, StartRoom.RoomPosition.y);
     //Return the room in this location
     return GetRoom(WestPosition);
 }
 private DungeonRoom GetSouthRoom(DungeonRoom StartRoom)
 {
     //Get the position of the north room
     Vector2 SouthPosition = new Vector2(StartRoom.RoomPosition.x, StartRoom.RoomPosition.y - 1);
     //Return the room in this location
     return GetRoom(SouthPosition);
 }
    //Returns the closest non void room to the room that is passed in
    private DungeonRoom GetClosestRoom(DungeonRoom TargetRoom, bool PathFromBoss)
    {
        DungeonRoom ClosestRoom = null;
        float ClosestRoomDistance = 0;

        //Loop through every room in the dungeon
        for ( int i = 0; i < RoomCount; i++ )
        {
            //Make sure this is not the room we are checking against
            if(DungeonRooms[i].DungeonFloor.transform.position == TargetRoom.DungeonFloor.transform.position)
                continue;

            //If the room is a void type room, skip to the next room
            if (DungeonRooms[i].RoomType == RoomTypes.VoidRoom)
                continue;

            //If we are ignoring pathing from the boss room, skip to the next room
            if (!PathFromBoss && DungeonRooms[i].RoomType == RoomTypes.BossRoom)
                continue;

            //If the ClosestRoomDistance is 0, we have nothing to compare to
            //so we store this room as the closest until we crosscheck it
            if (ClosestRoomDistance == 0)
            {
                ClosestRoom = DungeonStartRoom;
                ClosestRoomDistance = Vector3.Distance(ClosestRoom.DungeonFloor.transform.position, TargetRoom.DungeonFloor.transform.position);
                continue;
            }

            //Check if this room is closer than the current closest room
            if ( Vector3.Distance(DungeonRooms[i].DungeonFloor.transform.position, TargetRoom.DungeonFloor.transform.position) < ClosestRoomDistance)
            {
                //Store this as the new closest room
                ClosestRoom = DungeonRooms[i];
                ClosestRoomDistance = Vector3.Distance(DungeonRooms[i].DungeonFloor.transform.position, TargetRoom.DungeonFloor.transform.position);
            }
        }
        if (ClosestRoom == null)
            print("Get Closest Room returned null");
        return ClosestRoom;
    }
Example #31
0
 public DungeonRoom(IntPair position, DungeonRoom previousRoom) : this()
 {
     this.position     = new IntPair(position.x, position.y);
     this.previousRoom = previousRoom;
 }
    private void PlaceObjectives()
    {
        //Select a room where the player will start
        int StartRoomNumber = RNG.Next(0, (int)(DungeonSize.x * DungeonSize.y));
        //Select a second room, which isnt the same, for the boss
        int BossRoomNumber = StartRoomNumber;
        bool BossRoomPlaced = false;

        DungeonRoom StartRoom = GetRoom(0);
        DungeonRoom BossRoom = GetRoom(0);

        //If this exceeds 10, the required distance is probably too small
        //for the current size of the dungeon, if this happens we just
        //place the boss room somewhere that breaks this rule and print
        //an error message, so we dont get stuck in an infinite loop of
        //trying to find a place far enough away to place the boss room
        int BossRoomPlacementFailures = 0;

        while(!BossRoomPlaced)
        {
            //Find a spot to potentially place the boss room
            while (BossRoomNumber == StartRoomNumber)
                BossRoomNumber = RNG.Next(0, (int)(DungeonSize.x * DungeonSize.y));
            //Find these two rooms in the dungeon
            StartRoom = GetRoom(StartRoomNumber);
            BossRoom = GetRoom(BossRoomNumber);
            //If the required distance is 0, dont check for it, just place the rooms
            if (StartEndMinimumDistance == 0)
            {
                BossRoomPlaced = true;
                break;
            }
            //Check if these two rooms are far enough away as required by the distance
            //set in the inspector
            float StartBossDistance = Vector3.Distance(StartRoom.DungeonFloor.transform.position, BossRoom.DungeonFloor.transform.position);
            if (StartBossDistance >= StartEndMinimumDistance)
                BossRoomPlaced = true;
            else
            {
                //If the rooms are too close, reset the boss room number so it is placed again
                BossRoomNumber = StartRoomNumber;
                BossRoomPlacementFailures++;
                //If we have failed too many times, stop trying
                if(BossRoomPlacementFailures == 10)
                {
                    print("Failed to place boss room too many times, breaking distance rule to avoid infinite loop");
                    BossRoomPlaced = true;
                }
            }
        }
        //Change the types of these two rooms
        StartRoom.RoomType = RoomTypes.StartRoom;
        BossRoom.RoomType = RoomTypes.BossRoom;
        //Create the Start and Boss rooms indicators
        GameObject StartRoomIndicator = (GameObject)Instantiate(DungeonTeleporterPrefab, StartRoom.DungeonFloor.transform.position, Quaternion.identity);
        GameObject BossRoomIndicator = (GameObject)Instantiate(DungeonBossPrefab, BossRoom.DungeonFloor.transform.position, Quaternion.identity);
        //Set the room indicators as child objects to the room they are in
        StartRoomIndicator.transform.parent = StartRoom.DungeonFloor.transform;
        BossRoomIndicator.transform.parent = BossRoom.DungeonFloor.transform;
        //Store the room numbers of the Start and Boss rooms
        StartRoomNumber = StartRoom.RoomNumber;
        BossRoomNumber = BossRoom.RoomNumber;
        //Also store the two rooms for later access
        DungeonStartRoom = StartRoom;
        DungeonBossRoom = BossRoom;
    }
Example #33
0
    void RemoveUnusedObjects(DungeonRoom dr)
    {
        DungeonRoomInfo info = dr.Info;

        // DoorTriggers and Halls
        if (info.northWallType == DungeonRoomInfo.WallType.Closed)
        {
            if (!info.IsBombable(DungeonRoomInfo.WallDirection.North))
            {
                Destroy(dr.hall_N);
                Destroy(dr.doorTrigger_N);
                Destroy(dr.entranceBlock_N);
            }
        }
        if (info.eastWallType == DungeonRoomInfo.WallType.Closed)
        {
            if (!info.IsBombable(DungeonRoomInfo.WallDirection.East))
            {
                Destroy(dr.hall_E);
                Destroy(dr.doorTrigger_E);
                Destroy(dr.entranceBlock_E);
            }
        }
        if (info.southWallType == DungeonRoomInfo.WallType.Closed)
        {
            if (!info.IsBombable(DungeonRoomInfo.WallDirection.South))
            {
                Destroy(dr.hall_S);
                Destroy(dr.doorTrigger_S);
                Destroy(dr.entranceBlock_S);
            }
        }
        if (info.westWallType == DungeonRoomInfo.WallType.Closed)
        {
            if (!info.IsBombable(DungeonRoomInfo.WallDirection.West))
            {
                Destroy(dr.hall_W);
                Destroy(dr.doorTrigger_W);
                Destroy(dr.entranceBlock_W);
            }
        }

        // InnerBombable Walls
        if (!info.IsBombable(DungeonRoomInfo.WallDirection.North))
        {
            Destroy(dr.wall_bombedInner_N);
        }
        if (!info.IsBombable(DungeonRoomInfo.WallDirection.East))
        {
            Destroy(dr.wall_bombedInner_E);
        }
        if (!info.IsBombable(DungeonRoomInfo.WallDirection.South))
        {
            Destroy(dr.wall_bombedInner_S);
        }
        if (!info.IsBombable(DungeonRoomInfo.WallDirection.West))
        {
            Destroy(dr.wall_bombedInner_W);
        }

        // NpcContainer
        if (dr.IsNpcRoom)
        {
            dr.npcContainer.gameObject.SetActive(true);

            if (dr.ContainsBombUpgrade && info.BombUpgradeHasBeenPurchased)
            {
                Destroy(dr.rupeeTrigger);
            }
        }
        else
        {
            Destroy(dr.npcContainer.gameObject);
        }
    }
    private void ReconstructPath(DungeonRoom StartRoom, DungeonRoom EndRoom)
    {
        //Follow the EndRoom through its parents all the way back to the StartRoom
        //Placing indicators and changing room types as we go along
        print("reconstruction path");
        DungeonRoom CurrentRoom = EndRoom;
        int i = 0;
        while(true)
        {
            //If the CurrentRooms parent is the StartRoom, we have finished the path
            if (CurrentRoom == StartRoom)
            {
                print("reconstruction complete after " + i + " iterations");
                return;
            }

            //Follow the CurrentRoom to its parent
            CurrentRoom = CurrentRoom.ParentRoom;
            //If the room type is void, change it to path and place an indicator
            if(CurrentRoom.RoomType == RoomTypes.VoidRoom)
            {
                //Change room type
                SetToPathRoom(CurrentRoom);
                //Place indicator
                GameObject PathIndicator = (GameObject)Instantiate(DungeonPathPrefab, CurrentRoom.DungeonFloor.transform.position, Quaternion.identity);
                //Set indicator as child of the room
                PathIndicator.transform.parent = CurrentRoom.DungeonFloor.transform;
            }

            i++;
            //Break out if we get stuck in a loop too many times
            if(i>100)
            {
                print("Reconstruct Path iterations exceeded 100, breaking out to avoid inifinite loop.");
                print("If you are generating extremely large levels, this limit may need to be increased.");
            }
        }
    }
Example #35
0
    //Genera l'intero dungeon, il paramentro dungeon container è un semplice empty game object di contenimento, minshiftValue è il valore di spostamento
    //utilizzato dall'algoritmo di piazzamento delle stanze
    public void Generate(int minWidth, int maxWidth, int minHeight, int maxHeight, int roomNum, Dungeon dungeonContainer, int minShitValue)
    {
        //questo array serve per memorizzare i dati delle stanze
        //le stanze non vengono fisicamente allocate ma servono solo per l'algoritmo di piazzamento
        DungeonRoom[] roomArray = new DungeonRoom[roomNum];
        corridorsGO = new GameObject("corridors");

        //algoritmo di separazione
        for (int i = 0; i < roomNum; i++)
        {
            roomArray[i]             = new DungeonRoom(minWidth, maxWidth, minHeight, maxHeight);
            roomArray[i].Data.Origin = new IntVector2(0, 0);//l'origine delle stanze è sempre dal punto 0,0
            roomArray[i].Data.Name   = "Room: " + i;
            while (tileMatrix.checkOverLap(roomArray[i].Data.Origin, roomArray[i].Data.Width, roomArray[i].Data.Height))
            {
                int dir = Random.Range(0, 2);
                if (dir == 0)//muovo in orizzontale
                {
                    roomArray[i].moveRoom(minShitValue, 0);
                }
                else if (dir == 1) //muovo in verticale
                {
                    roomArray[i].moveRoom(0, minShitValue);
                }
            }
            updateTileMatrix(roomArray[i]);
        }//fine algoritmo di separazione

        //comincia la creazione delle stanze nello spazio 3D
        DungeonRoom[] gameObjectRoomArray = new DungeonRoom[roomNum];//queste invece vengono effettivamente allocate
        for (int i = 0; i < roomNum; i++)
        {
            gameObjectRoomArray[i] = Instantiate(dungeonRoomPrefab) as DungeonRoom;
            gameObjectRoomArray[i].transform.parent = dungeonContainer.transform;
            gameObjectRoomArray[i].generateRoom(roomArray[i]);
            gameObjectRoomArray[i].Data.Name = roomArray[i].Data.Name;
            gameObjectRoomArray[i].name      = gameObjectRoomArray[i].Data.Name;
            gameObjectRoomArray[i].transform.localPosition = new Vector3(roomArray[i].Data.Origin.x, 0, roomArray[i].Data.Origin.z);
            gameObjectRoomArray[i].AllocateRoomInSpace();
            updateDungeonActiveCells(roomArray[i].Data.Origin, gameObjectRoomArray[i]);//utilizzo un dizionario per mantenermi le mattonelle attive all'interno del dungeon corridoi + stanze
        }

        //algoritmo di connessione O(n^3), crea prima il gravo RNG e poi connette le stanze con percorsi rettangolari
        int  ijDist, ikDist, jkDist;
        bool skip = false;

        for (int i = 0; i < roomNum; i++)
        {
            for (int j = i + 1; j < roomNum; j++)
            {
                skip   = false;
                ijDist = roomArray[i].distance(roomArray[j]);
                //per ogni coppia di stanze (i,j) controllo che non esista un terzo nodo k t.c Mathf.Max(ikDist, jkDist) < ijDist
                //se esiste break dal questo for e quindi significa che non esiste l'arco i,j
                for (int k = 0; k < roomNum; k++)
                {
                    if (k == i || k == j)
                    {
                        continue;
                    }
                    ikDist = roomArray[i].distance(roomArray[k]);
                    jkDist = roomArray[j].distance(roomArray[k]);
                    if (Mathf.Max(ikDist, jkDist) < ijDist)
                    {
                        skip = true;
                        break;
                    }
                }
                if (!skip)
                {//se la prima coppia scelta i,j non è stata scartata vuol dire che il suo arco può essere aggiunto al grafo
                    Gizmos.color = Color.blue;
                    Vector3 c1 = new Vector3(roomArray[i].Data.Center.x, 3, roomArray[i].Data.Center.z);
                    Vector3 c2 = new Vector3(roomArray[j].Data.Center.x, 3, roomArray[j].Data.Center.z);
                    centerList.Add(new centerPair(c1, c2)); //serve per disegnare il grafo rosso di overlay

                    //ora quindi si crea il corridoio tra i e j
                    createCorridor(corridorsGO, gameObjectRoomArray[i], gameObjectRoomArray[j]); // va passato il gameobject istanziato nello spazio e non il roomArray[i]
                    corridorsGO.transform.parent = transform;
                    //print("ROOM " + gameObjectRoomArray[i] + " --- connected to ROOM --- " + gameObjectRoomArray[j]);
                }
            }
        }//fine algoritmo di connessione
        //foreach (KeyValuePair<IntVector2, DungeonCell> entry in activeDungeonCells)
        //{
        //    print("key: " + entry.Key + ", value: " + entry.Value);
        //}
        print(tileMatrix);
    }    //fine generate
Example #36
0
 public BossRoom(IntPair position, DungeonRoom previousRoom, float difficulty)
     : base(position, previousRoom)
 {
     this.difficulty = difficulty;
 }
Example #37
0
 void PlaceRoomOnMap(DungeonRoom room)
 {
     for (int x = room.UpperLeftX - roomSurroundings; x < room.LowerRightX + roomSurroundings; x++)
     {
         for (int y = room.UpperLeftY - roomSurroundings; y < room.LowerRightY + roomSurroundings; y++)
         {
             if (x == room.UpperLeftX - roomSurroundings || x == room.LowerRightX + (roomSurroundings - 1))
             {
                 dungeonMap[x, y] = SURROUNDING_WALL_TILE;
             }
             else if (y == room.UpperLeftY - roomSurroundings || y == room.LowerRightY + (roomSurroundings - 1))
             {
                 dungeonMap[x, y] = SURROUNDING_WALL_TILE;
             }
             else if (x == room.UpperLeftX - (roomSurroundings - 1) || x == room.LowerRightX)
             {
                 dungeonMap[x, y] = VERTICAL_WALL_TILE;
             }
             else if (y == room.UpperLeftY - (roomSurroundings - 1) || y == room.LowerRightY)
             {
                 dungeonMap[x, y] = HORIZONTAL_WALL_TILE;
             }
             else
             {
                 dungeonMap[x, y] = FLOOR_TILE_0;
             }
             dungeonMap[room.UpperLeftX - 1, room.UpperLeftY - 1] = CORNER_TILE;
             dungeonMap[room.UpperLeftX - 1, room.LowerRightY] = CORNER_TILE;
             dungeonMap[room.LowerRightX, room.UpperLeftY - 1] = CORNER_TILE;
             dungeonMap[room.LowerRightX, room.LowerRightY] = CORNER_TILE;
         }
     }
     int columns = Program.rand.Next(MAX_COLUMNS_IN_ROOM);
     for (int i = 0; i < columns; i++)
     {
         PlaceObjectInsideRoom(COLUMN_TILE, room);
     }
         AddRoomToDungeon(room);
 }
 //Takes in a list and a room, adds any rooms adjacent that can be moved in between
 private void AddAdjacentRooms(DungeonRoom TargetRoom, List<DungeonRoom> TargetList)
 {
     //Get the positions the 4 adjacent rooms would be in
     Vector2 NorthPos = new Vector2(TargetRoom.RoomPosition.x, TargetRoom.RoomPosition.y + 1);
     Vector2 EastPos = new Vector2(TargetRoom.RoomPosition.x + 1, TargetRoom.RoomPosition.y);
     Vector2 SouthPos = new Vector2(TargetRoom.RoomPosition.x, TargetRoom.RoomPosition.y - 1);
     Vector2 WestPos = new Vector2(TargetRoom.RoomPosition.x - 1, TargetRoom.RoomPosition.y);
     //Check if these room positions are within the bounds of the dungeon size
     bool NorthPosValid = NorthPos.x >= DungeonSize.x ||
                          NorthPos.y >= DungeonSize.y ||
                          NorthPos.x < 0 ||
                          NorthPos.y < 0
                          ? false : true;
     bool EastPosValid = EastPos.x >= DungeonSize.x ||
                         EastPos.y >= DungeonSize.y ||
                         EastPos.x < 0 ||
                         EastPos.y < 0
                         ? false : true;
     bool SouthPosValid = SouthPos.x >= DungeonSize.x ||
                          SouthPos.y >= DungeonSize.y ||
                          SouthPos.x < 0 ||
                          SouthPos.y < 0
                          ? false : true;
     bool WestPosValid = WestPos.x >= DungeonSize.x ||
                         WestPos.y >= DungeonSize.y ||
                         WestPos.x < 0 ||
                         WestPos.y < 0
                         ? false : true;
     //Get the four adjacent rooms if they are valid
     DungeonRoom NorthRoom = NorthPosValid ? GetNorthRoom(TargetRoom) : null;
     DungeonRoom EastRoom = EastPosValid ? GetEastRoom(TargetRoom) : null;
     DungeonRoom SouthRoom = SouthPosValid ? GetSouthRoom(TargetRoom) : null;
     DungeonRoom WestRoom = WestPosValid ? GetWestRoom(TargetRoom) : null;
     //Add the adjacent valid rooms to the list
     if (NorthPosValid)
         TargetList.Add(NorthRoom);
     if (EastPosValid)
         TargetList.Add(EastRoom);
     if (SouthPosValid)
         TargetList.Add(SouthRoom);
     if (WestPosValid)
         TargetList.Add(WestRoom);
 }
    GameObject getRoomTwo(Vector3 pos)
    {
        GameObject drHolder = new GameObject("Room2");
        drHolder.transform.position = pos;
        drHolder.transform.parent = roomHolder.transform;

        DungeonRoom dr = new DungeonRoom();
        dr.room = Instantiate(roomTB, pos, Quaternion.identity) as GameObject;
        dr.room.transform.parent = drHolder.transform;

        return drHolder;
    }
 private int CalculateHScore(DungeonRoom FirstRoom, DungeonRoom SecondRoom)
 {
     //We use the manhattan distance method to find the h score
     int XDistance = (int)(FirstRoom.RoomPosition.x > SecondRoom.RoomPosition.x ? FirstRoom.RoomPosition.x - SecondRoom.RoomPosition.x : SecondRoom.RoomPosition.x - FirstRoom.RoomPosition.x);
     int YDistance = (int)(FirstRoom.RoomPosition.y > SecondRoom.RoomPosition.y ? FirstRoom.RoomPosition.y - SecondRoom.RoomPosition.y : SecondRoom.RoomPosition.y - FirstRoom.RoomPosition.y);
     return XDistance + YDistance;
 }
    //Takes in what is presumed to be a void type room and turns it into a path type
    //room, spawns a box to indicate this
    private void SetToPathRoom(DungeonRoom TargetRoom)
    {
        //If this is not a void room, dont do anything
        if (TargetRoom.RoomType != RoomTypes.VoidRoom)
            return;

        //Change the rooms type
        TargetRoom.RoomType = RoomTypes.PathRoom;
        //Add an indicator to show what type this room is
        GameObject DungeonPath = (GameObject)Instantiate(DungeonPathPrefab, TargetRoom.DungeonFloor.transform.position, Quaternion.identity);
        //Set the indicator as a child object to the room its indicating
        DungeonPath.transform.parent = TargetRoom.DungeonFloor.transform;
    }
    GameObject getRoomZero(Vector3 pos)
    {
        GameObject drHolder = new GameObject("Room0");
        drHolder.transform.position = pos;
        drHolder.transform.parent = roomHolder.transform;

        DungeonRoom dr = new DungeonRoom();
        dr.room = Instantiate(roomB, pos, Quaternion.identity) as GameObject;
        dr.room.transform.parent = drHolder.transform;

        GameObject objHolder = new GameObject("Objs");
        objHolder.transform.position = pos;
        objHolder.transform.parent = drHolder.transform;

        const int NUM_OBJS = 39;
        dr.objs = new GameObject[NUM_OBJS];

        // top left corner
        dr.objs[0] = Instantiate(water, new Vector3(pos.x - 5.5f, pos.y + 3, 0), Quaternion.identity) as GameObject;
        dr.objs[1] = Instantiate(water, new Vector3(pos.x - 4.5f, pos.y + 3, 0), Quaternion.identity) as GameObject;
        dr.objs[2] = Instantiate(water, new Vector3(pos.x - 3.5f, pos.y + 3, 0), Quaternion.identity) as GameObject;
        dr.objs[3] = Instantiate(water, new Vector3(pos.x - 5.5f, pos.y + 2, 0), Quaternion.identity) as GameObject;

        // top right corner
        dr.objs[4] = Instantiate(water, new Vector3(pos.x + 5.5f, pos.y + 3, 0), Quaternion.identity) as GameObject;
        dr.objs[5] = Instantiate(water, new Vector3(pos.x + 4.5f, pos.y + 3, 0), Quaternion.identity) as GameObject;
        dr.objs[6] = Instantiate(water, new Vector3(pos.x + 1.5f, pos.y + 1, 0), Quaternion.identity) as GameObject;
        dr.objs[7] = Instantiate(water, new Vector3(pos.x + 5.5f, pos.y + 2, 0), Quaternion.identity) as GameObject;

        // bot right corner
        dr.objs[8] = Instantiate(water, new Vector3(pos.x + 5.5f, pos.y - 3, 0), Quaternion.identity) as GameObject;
        dr.objs[9] = Instantiate(water, new Vector3(pos.x + 4.5f, pos.y - 3, 0), Quaternion.identity) as GameObject;
        dr.objs[10] = Instantiate(water, new Vector3(pos.x + 3.5f, pos.y - 3, 0), Quaternion.identity) as GameObject;
        dr.objs[11] = Instantiate(water, new Vector3(pos.x + 5.5f, pos.y - 2, 0), Quaternion.identity) as GameObject;

        // bot left corner
        dr.objs[12] = Instantiate(water, new Vector3(pos.x - 5.5f, pos.y - 3, 0), Quaternion.identity) as GameObject;
        dr.objs[13] = Instantiate(water, new Vector3(pos.x - 4.5f, pos.y - 3, 0), Quaternion.identity) as GameObject;
        dr.objs[14] = Instantiate(water, new Vector3(pos.x - 3.5f, pos.y - 3, 0), Quaternion.identity) as GameObject;
        dr.objs[15] = Instantiate(water, new Vector3(pos.x - 5.5f, pos.y - 2, 0), Quaternion.identity) as GameObject;

        dr.objs[16] = Instantiate(water, new Vector3(pos.x - 2.5f, pos.y - 3, 0), Quaternion.identity) as GameObject;
        dr.objs[17] = Instantiate(water, new Vector3(pos.x - 1.5f, pos.y - 3, 0), Quaternion.identity) as GameObject;

        dr.objs[18] = Instantiate(water, new Vector3(pos.x + 2.5f, pos.y - 3, 0), Quaternion.identity) as GameObject;
        dr.objs[19] = Instantiate(water, new Vector3(pos.x + 1.5f, pos.y - 3, 0), Quaternion.identity) as GameObject;
        dr.objs[20] = Instantiate(water, new Vector3(pos.x - 5.5f, pos.y - 1, 0), Quaternion.identity) as GameObject;
        dr.objs[21] = Instantiate(water, new Vector3(pos.x + 5.5f, pos.y + 1, 0), Quaternion.identity) as GameObject;

        dr.objs[22] = Instantiate(water, new Vector3(pos.x + 1.5f, pos.y + 2, 0), Quaternion.identity) as GameObject;
        dr.objs[23] = Instantiate(water, new Vector3(pos.x + 0.5f, pos.y - 1, 0), Quaternion.identity) as GameObject;
        dr.objs[24] = Instantiate(water, new Vector3(pos.x - 0.5f, pos.y - 1, 0), Quaternion.identity) as GameObject;

        dr.objs[25] = Instantiate(water, new Vector3(pos.x - 1.5f, pos.y - 1, 0), Quaternion.identity) as GameObject;
        dr.objs[26] = Instantiate(water, new Vector3(pos.x - 1.5f, pos.y + 0, 0), Quaternion.identity) as GameObject;
        dr.objs[27] = Instantiate(water, new Vector3(pos.x - 1.5f, pos.y + 1, 0), Quaternion.identity) as GameObject;

        dr.objs[28] = Instantiate(water, new Vector3(pos.x + 1.5f, pos.y - 2, 0), Quaternion.identity) as GameObject;
        dr.objs[29] = Instantiate(water, new Vector3(pos.x + 1.5f, pos.y - 1, 0), Quaternion.identity) as GameObject;
        dr.objs[30] = Instantiate(water, new Vector3(pos.x + 2.5f, pos.y - 2, 0), Quaternion.identity) as GameObject;
        dr.objs[31] = Instantiate(water, new Vector3(pos.x + 2.5f, pos.y - 1, 0), Quaternion.identity) as GameObject;

        dr.objs[32] = Instantiate(water, new Vector3(pos.x - 4.5f, pos.y - 2, 0), Quaternion.identity) as GameObject;
        dr.objs[33] = Instantiate(water, new Vector3(pos.x - 4.5f, pos.y - 1, 0), Quaternion.identity) as GameObject;

        dr.objs[34] = Instantiate(water, new Vector3(pos.x - 0.5f, pos.y + 1, 0), Quaternion.identity) as GameObject;
        dr.objs[35] = Instantiate(water, new Vector3(pos.x + 0.5f, pos.y + 1, 0), Quaternion.identity) as GameObject;

        dr.objs[36] = Instantiate(water, new Vector3(pos.x - 0.5f, pos.y + 2, 0), Quaternion.identity) as GameObject;
        dr.objs[37] = Instantiate(water, new Vector3(pos.x + 0.5f, pos.y + 2, 0), Quaternion.identity) as GameObject;

        foreach(GameObject g in dr.objs)
        {
            waterTiles.Add(g);
        }

        if(!keyIsFound){
            dr.objs[38] = Instantiate(key, new Vector3(pos.x + -0.5f, pos.y, 0), Quaternion.identity) as GameObject;
        }

        for(int i=0; i < NUM_OBJS; ++i){
            if(i == 38 && keyIsFound){
                continue;
            }

            dr.objs[i].GetComponent<SpriteRenderer>().sortingOrder = 2;
            dr.objs[i].transform.parent = objHolder.transform;
        }

        return drHolder;
    }
Example #43
0
    public static List <DungeonRoomEnemy> GenerateChallenge(float difficulty, DungeonRoom room)
    {
        List <DungeonRoomEnemy> enemies = new List <DungeonRoomEnemy>();

        return(enemies);
    }
Example #44
0
 public bool CellInsideRoomBounds(DungeonRoom room, int x, int y)
 {
     return (x >= (room.UpperLeftX - roomSurroundings) && x < (room.LowerRightX + roomSurroundings))
         && (y >= (room.UpperLeftY - roomSurroundings) && y < (room.LowerRightY + roomSurroundings));
 }
Example #45
0
 public void generateRoom(DungeonRoom aRoom)
 {
     data = aRoom.Data;
 }
Example #46
0
    /// <summary>
    /// Creates the simple dungeon map with size depending on the amount of rooms.
    /// </summary>
    /// <returns>LabMapContainer object</returns>
    /// <param name="roomsAmount">How many rooms will the dungeon have.</param>
    /// /// <param name="hasExitToNextFloor">True if this dungeon is not the last floor of the dungeon system.</param>
    /// /// <param name="specialRooms">Optional array of rooms with custom RoomType</param>
    public LabMapContainer CreateSimpleDungeonMap(int roomsAmount, bool hasExitToNextFloor, params DungeonRoom[] specialRooms)
    {
        //Assess approximatie dungeon dimensions
        int approxDungeonArea = (int)(dungeonStretchCoeff * (roomsAmount + specialRooms.Length) * ((minRoomWidth * minRoomHeight) + (maxRoomWidth * maxRoomHeight)) / 2);
        columns = (int)Math.Sqrt(approxDungeonArea);
        rows = columns;
        fogOfWarMap = new bool[columns, rows];
        dungeonMap = new int[columns, rows];
        rooms = new List<DungeonRoom>();
        //fill dungeon with walls
        for (int x = 0; x < columns; x++)
        {
            for (int y = 0; y < rows; y++)
            {
                dungeonMap[x, y] = WALL_TILE;
            }
        }

        //create rooms array and place them on map
        for (int i = 0; i < roomsAmount; i++)
        {
            DungeonRoom roomToAdd = GenerateNewRoom();
            rooms.Add(roomToAdd);
            PlaceRoomOnMap(roomToAdd);
        }

        foreach (DungeonRoom specialRoom in specialRooms)
        {
            DungeonRoom targetRoom = GenerateNewRoom();
            if (targetRoom == null)
            {
                Console.WriteLine("Couldn't find a place for a secret room =(((");
                continue;
            }
            targetRoom.roomType = specialRoom.roomType;
            rooms.Add(targetRoom);
            PlaceRoomOnMap(targetRoom);
        }
        PlaceDoorsOnMap();

        int startRoomNumber = Program.rand.Next(0, rooms.Count);
        while (rooms[startRoomNumber].roomType != RoomType.RegularlRoom)
        {
            startRoomNumber = Program.rand.Next(0, rooms.Count);
        }
        startRoom = rooms[startRoomNumber];
        dungeonMap[startRoom.CenterX, startRoom.CenterY] = START_TILE;

        if (hasExitToNextFloor)
        {
            int exitRoomNumber = Program.rand.Next(0, rooms.Count);
            while (exitRoomNumber == startRoomNumber || rooms[exitRoomNumber].roomType != RoomType.RegularlRoom)
            {
                exitRoomNumber = Program.rand.Next(0, rooms.Count);
            }
            exitRoom = rooms[exitRoomNumber];
            dungeonMap[exitRoom.CenterX, exitRoom.CenterY] = EXIT_TILE;
        }

        renderingMap = CreateRenderingMap(dungeonMap);
        walkableMap = CreateWalkableMap(renderingMap);
        //return CreateRenderingMap(dungeonMap);
        return new LabMapContainer(dungeonMap, renderingMap, fogOfWarMap, walkableMap, rooms);
    }
 private void LockHorizontally(DungeonRoom left, DungeonRoom right, int lockID)
 {
     ConnectHorizontally(left, right);
     left.Lock(Direction.Right, lockID);
     right.Lock(Direction.Left, lockID);
 }
    GameObject getRoomSix(Vector3 pos)
    {
        GameObject drHolder = new GameObject("Room6");
        drHolder.transform.position = pos;
        drHolder.transform.parent = roomHolder.transform;

        DungeonRoom dr = new DungeonRoom();
        dr.room = Instantiate(roomRBL, pos, Quaternion.identity) as GameObject;
        dr.room.transform.parent = drHolder.transform;

        GameObject objHolder = new GameObject("Objs");
        objHolder.transform.position = pos;
        objHolder.transform.parent = drHolder.transform;

        dr.objs = new GameObject[10];

        // smiley face
        dr.objs[0] = Instantiate(block, new Vector3(pos.x - 1.5f, pos.y + 2, 0), Quaternion.identity) as GameObject;
        dr.objs[1] = Instantiate(block, new Vector3(pos.x + 1.5f, pos.y + 2, 0), Quaternion.identity) as GameObject;
        dr.objs[2] = Instantiate(block, new Vector3(pos.x - 2.5f, pos.y, 0), Quaternion.identity) as GameObject;
        dr.objs[3] = Instantiate(block, new Vector3(pos.x - 1.5f, pos.y, 0), Quaternion.identity) as GameObject;
        dr.objs[4] = Instantiate(block, new Vector3(pos.x - 0.5f, pos.y - 1, 0), Quaternion.identity) as GameObject;
        dr.objs[5] = Instantiate(block, new Vector3(pos.x + 0.5f, pos.y - 1, 0), Quaternion.identity) as GameObject;
        dr.objs[6] = Instantiate(block, new Vector3(pos.x + 1.5f, pos.y, 0), Quaternion.identity) as GameObject;
        dr.objs[7] = Instantiate(block, new Vector3(pos.x + 2.5f, pos.y, 0), Quaternion.identity) as GameObject;

        // floor mat
        dr.objs[8] = Instantiate(mat, new Vector3(pos.x - 0.5f, pos.y - 3, 0), Quaternion.identity) as GameObject;
        dr.objs[9] = Instantiate(mat, new Vector3(pos.x + 0.5f, pos.y - 3, 0), Quaternion.identity) as GameObject;

        for(int i=0; i < 10; ++i){
            dr.objs[i].GetComponent<SpriteRenderer>().sortingOrder = 2;
            dr.objs[i].transform.parent = objHolder.transform;
        }

        return drHolder;
    }
 public bool Connects(DungeonRoom room)
 {
     return(RoomA == room || RoomB == room);
 }
Example #50
0
    /// <summary>
    /// Adds the room to the dungeon and connects it with the closest dungeon cell.
    /// </summary>
    /// <param name="target">Room to add</param>
    void AddRoomToDungeon(DungeonRoom target)
    {
        if (rooms.Count < 2) return;
        int[] closestDungeonCell = { 9999, 9999 };
        int closestDistance = Math.Abs(closestDungeonCell[0] - target.CenterX) + Math.Abs(closestDungeonCell[1] - target.CenterY);
        for (int x = 0; x < columns; x++)
        {
            for (int y = 0; y < rows; y++)
            {
                if (CellInsideRoomBounds(target, x, y) || (dungeonMap[x, y] != FLOOR_TILE_0 && dungeonMap[x, y] != DOOR_TILE))
                {
                    continue;
                }
                else
                {
                    int distance = Math.Abs(x - target.CenterX) + Math.Abs(y - target.CenterY);
                    if (distance <= closestDistance)
                    {
                        if (target.roomType == RoomType.SecretRoom)
                        {
                            //Check that secret rooms are attached only to other rooms, not to coridors
                            if (!CellInsideAnyRoom(x, y))
                            {
                                continue;
                            }
                        }
                        closestDistance = distance;
                        closestDungeonCell[0] = x;
                        closestDungeonCell[1] = y;
                    }
                }

            }
        }
        //		Console.WriteLine("Target room center coordinates are {0}:{1}.", target.CenterX, target.CenterY);
        //		Console.WriteLine("Target room left corner coordinates are {0}:{1}.", target.UpperLeftX, target.UpperLeftY);
        //		Console.WriteLine("Target room right corner coordinates are {0}:{1}.", target.LowerRightX, target.LowerRightY);
        //		Console.WriteLine("Trying to connect room with cell {0}:{1}.", closestDungeonCell[0], closestDungeonCell[1]);
        //		Console.WriteLine("Is this cell inside the room? {0}", CellInsideRoomBounds(target, closestDungeonCell[0], closestDungeonCell[1]));
        ConnectRoomWithCell(target, closestDungeonCell[0], closestDungeonCell[1]);
    }
Example #51
0
 public void SetNeighbourRoom(DungeonRoom neighbour, Direction direction)
 => neighbourRooms[direction] = neighbour;
Example #52
0
    void ConnectRoomWithCell(DungeonRoom room1, int targetX, int targetY)
    {
        int x1 = room1.CenterX;
        int y1 = room1.CenterY;
        int x2 = targetX;
        int y2 = targetY;

        int xDir = (x2 > x1) ? 1 : -1;
        int yDir = (y2 > y1) ? 1 : -1;

        //horizontal corridor
        for (int x = x1; x != x2 + xDir; x += xDir)
        {
            if (dungeonMap[x, y1] == CORNER_TILE || dungeonMap[x, y1] == HORIZONTAL_WALL_TILE)
            {
                y1 += yDir;
                dungeonMap[x - xDir, y1] = FLOOR_TILE_0;
                dungeonMap[x, y1] = FLOOR_TILE_0;
            }
            else
            {
                if (dungeonMap[x, y1] == FOG_TRIGGER_TILE || dungeonMap[x, y1] == SECRET_DOOR_TILE)
                {
                    continue;
                }
                else
                {
                    if (dungeonMap[x, y1] == VERTICAL_WALL_TILE && room1.roomType == RoomType.SecretRoom)
                    {
                        dungeonMap[x, y1] = SECRET_DOOR_TILE;
                    }
                    else
                    {
                        dungeonMap[x, y1] = FLOOR_TILE_0;
                    }
                }
            }
        }

        //vertical corridor
        for (int y = y1; y != y2 + yDir; y += yDir)
        {
            if (dungeonMap[x2, y] == CORNER_TILE || dungeonMap[x2, y] == VERTICAL_WALL_TILE)
            {
                x2 += xDir;
                dungeonMap[x2, y - yDir] = FLOOR_TILE_0;
                dungeonMap[x2, y] = FLOOR_TILE_0;
            }
            else
            {
                if (dungeonMap[x2, y] == FOG_TRIGGER_TILE || dungeonMap[x2, y] == SECRET_DOOR_TILE)
                {
                    continue;
                }
                else
                {
                    if (dungeonMap[x2, y] == HORIZONTAL_WALL_TILE && room1.roomType == RoomType.SecretRoom)
                    {
                        dungeonMap[x2, y] = SECRET_DOOR_TILE;
                    }
                    else
                    {
                        dungeonMap[x2, y] = FLOOR_TILE_0;
                    }
                }
            }
        }

           // dungeonMap[x2, y1] = FOG_TRIGGER_TILE;
        //dungeonMap[x2, y2] = FOG_TRIGGER_TILE;
    }
Example #53
0
 void DiscoverRoom(DungeonRoom room)
 {
     for (int x = room.UpperLeftX - 1; x < room.LowerRightX + 1; x++)
     {
         for (int y = room.UpperLeftY - 1; y < room.LowerRightY + 1; y++)
         {
             fogOfWarMap[x, y] = true;
         }
     }
 }
Example #54
0
 DungeonRoom FindNearestRoom(DungeonRoom target)
 {
     if (rooms.Count <= 1)
     {
         return null;
     }
     else
     {
         int targetX = target.CenterX;
         int targetY = target.CenterY;
         int nearestDistance = 0;
         DungeonRoom nearestRoom = null;
         foreach (DungeonRoom room in rooms)
         {
             int distance = (int)(Math.Abs(room.CenterX - target.CenterX) + Math.Abs(room.CenterY - target.CenterY));
             if (nearestDistance != 0 && (room.CenterX != targetX || room.CenterY != targetY))
             {
                 if (distance < nearestDistance)
                 {
                     nearestDistance = distance;
                     nearestRoom = room;
                 }
             }
             else if (nearestDistance == 0 && (room.CenterX != targetX || room.CenterY != targetY))
             {
                 nearestDistance = (int)(Math.Abs(room.CenterX - target.CenterX) + Math.Abs(room.CenterY - target.CenterY));
                 nearestRoom = room;
             }
         }
         return nearestRoom;
     }
 }
Example #55
0
    void CreateHolesInFloor()
    {
        if (holeMarkersContainer == null)
        {
            return;
        }

        foreach (Transform hole in holeMarkersContainer)
        {
            HoleMarker holeMarker = hole.GetComponent <HoleMarker>();
            if (holeMarker == null)
            {
                continue;
            }

            DungeonRoom dr = DungeonRoom.GetRoomForPosition(hole.position);
            if (dr == null)
            {
                //print(" hole -> " + hole.name + ": " + hole.transform.position.x + ", " + hole.transform.position.z);
                continue;
            }

            Vector2 tile             = dr.WorldPointToTile(hole.position);
            Rect    floorTextureArea = dr.TileToFloorTextureArea(tile);

            //print("tile: " + tile.ToString());
            //print("floorTextureArea: " + floorTextureArea.ToString());

            // Create a new texture
            Texture2D origTexture;
            if (holeMarker.appearsOnPushBlock && dr.Info.PushBlockChangeFloorMaterial != null)
            {
                origTexture = dr.Info.PushBlockChangeFloorMaterial.mainTexture as Texture2D;
            }
            else
            {
                origTexture = dr.floor.GetComponent <Renderer>().material.mainTexture as Texture2D;
            }

            Texture2D newTexture = new Texture2D(origTexture.width, origTexture.height);
            newTexture.filterMode = origTexture.filterMode;

            // Copy the pixels and cut the hole
            Color[] pixels = origTexture.GetPixels();
            int     y      = (int)floorTextureArea.yMin;
            while (y < (int)floorTextureArea.yMax)
            {
                int x = (int)floorTextureArea.xMin;
                while (x < (int)floorTextureArea.xMax)
                {
                    int i = newTexture.width * y + x;
                    pixels[i].a = 0;
                    pixels[i].r = 0.9f;
                    pixels[i].g = 0.8f;
                    pixels[i].b = 0.7f;
                    ++x;
                }
                ++y;
            }
            newTexture.SetPixels(pixels);
            newTexture.Apply();

            // Assign the new texture
            if (holeMarker.appearsOnPushBlock)
            {
                dr.Info.PushBlockChangeFloorMaterial             = new Material(dr.floor.GetComponent <Renderer>().material);
                dr.Info.PushBlockChangeFloorMaterial.mainTexture = newTexture;
            }
            else
            {
                dr.Info.floorMaterial.mainTexture = newTexture;
                dr.floor.GetComponent <Renderer>().material.mainTexture = newTexture;
            }
        }
    }
Example #56
0
    DungeonRoom GenerateNewRoom()
    {
        int roomX = Program.rand.Next(4, columns - maxRoomWidth - 4);
        int roomY = Program.rand.Next(4, rows - maxRoomHeight - 4);
        int roomWidth = Program.rand.Next(minRoomWidth, maxRoomWidth);
        int roomHeight = Program.rand.Next(minRoomHeight, maxRoomHeight);
        DungeonRoom targetRoom = new DungeonRoom(roomX, roomY, roomWidth, roomHeight);
        int iterations = 0;

        while (!AbleToPlace(targetRoom))
        {
            roomX = Program.rand.Next(4, columns - maxRoomWidth - 4);
            roomY = Program.rand.Next(4, rows - maxRoomHeight - 4);
            targetRoom = new DungeonRoom(roomX, roomY, roomWidth, roomHeight);
            iterations++;
            if (iterations > 14000) return null;
        }

        return targetRoom;
    }
Example #57
0
 public TreasureRoom(IntPair position, DungeonRoom previousRoom)
     : base(position, previousRoom)
 {
 }
Example #58
0
 void PlaceObjectInsideRoom(int objectType, DungeonRoom room)
 {
     int x = Program.rand.Next(room.UpperLeftX, room.LowerRightX);
     int y = Program.rand.Next(room.UpperLeftY, room.LowerRightY);
     if (dungeonMap[x, y] == FLOOR_TILE_0)
     {
         dungeonMap[x, y] = objectType;
     }
     else
     {
         PlaceObjectInsideRoom(objectType, room);
     }
 }
Example #59
0
 bool AbleToPlace(DungeonRoom room)
 {
     int count = 0;
     for (int x = room.UpperLeftX - roomSurroundings; x < room.LowerRightX + roomSurroundings; x++)
     {
         for (int y = room.UpperLeftY - roomSurroundings; y < room.LowerRightY + roomSurroundings; y++)
         {
             if (dungeonMap[x, y] != WALL_TILE)
             {
                 count++;
                 return false;
             }
             else count++;
         }
     }
     return true;
 }
    GameObject getRoomThree(Vector3 pos)
    {
        // boss room

        GameObject drHolder = new GameObject("Room3");
        drHolder.transform.position = pos;
        drHolder.transform.parent = roomHolder.transform;

        DungeonRoom dr = new DungeonRoom();
        dr.room = Instantiate(roomG, pos, Quaternion.identity) as GameObject;//roomBombN
        dr.room.transform.parent = drHolder.transform;

        GameObject objHolder = new GameObject("Objs");
        objHolder.transform.position = pos;
        objHolder.transform.parent = drHolder.transform;

        dr.objs = new GameObject[1];

        /*dr.objs[0] = Instantiate(stairs, new Vector3(pos.x + 0.5f, pos.y, 0), Quaternion.identity) as GameObject;
        dr.objs[0].GetComponent<DungeonStairs>().isRoomBoss = true;

        for(int i=0; i < 1; ++i){
            dr.objs[i].GetComponent<SpriteRenderer>().sortingOrder = 2;
            dr.objs[i].transform.parent = objHolder.transform;
        }*/

        return drHolder;
    }