Пример #1
0
 // Use this for initialization
 void Start()
 {
     if (m_roomCoord == null)
     {
         m_roomCoord = new CTRoomCoordinate(0, 0);
     }
 }
Пример #2
0
    public void Init(CTRoomCoordinate _spawnCoord)
    {
        m_RoomCoord = new CTRoomCoordinate(_spawnCoord);

        m_EnemyStats = new CStats();
        SetStats(25,           //lvl
                 100, 1250, 0, //exp,maxExp,expBoost
                 1000, 1000,   //HP
                 100, 100,     //SP
                 250,          //atk
                 250,          //def
                 3,            //playrate
                 2);           //movespeed
        m_IsImmortal  = false;
        m_EnemySprite = GetComponent <SpriteRenderer>().sprite;

        m_SM = new CStateMachine();
        m_SM.AddState(new CStateBossIdle(this.gameObject, transform.position));
        m_SM.AddState(new CStateBossChase(this.gameObject));
        m_SM.AddState(new CStateBossTeleport(this.gameObject, CTDungeon.Instance.Floors[CTDungeon.Instance.currentFloor].Rooms[1]));
        m_SM.AddState(new CStateBossAttack(this.gameObject));
        m_SM.AddState(new CStateDead(this.gameObject));

        m_SM.SetNextState("StateIdle");
    }
Пример #3
0
 public CTRoom GetRoomFromCoord(CTRoomCoordinate _coord)
 {
     foreach (CTRoom currRm in m_Rooms)
     {
         if (currRm.coordinate.sameAs(_coord))
         {
             return(currRm);
         }
     }
     return(null);
 }
Пример #4
0
 public CTRoom()
 {
     generated     = false;
     firstRoom     = false;
     roomDepth     = 0;
     xPos          = yPos = 0;
     roomWidth     = roomHeight = 0;
     prevCorridor  = Direction.Size;
     coordinate    = new CTRoomCoordinate(0, 0);
     nextCorridors = new Dictionary <Direction, CTCorridor>();
     pathnodes     = new Dictionary <PathNodeDir, CPathNode>();
 }
Пример #5
0
    /******************
    * BOSS FLOOR ONLY
    ******************/
    public void SetupRoom(int _column, int _row, int _width, int _height, CTRoomCoordinate _coordinate, CTCorridor _prevCorridor = null)
    {
        //For 1st room custom creation
        roomWidth  = _width;
        roomHeight = _height;
        coordinate = new CTRoomCoordinate(_coordinate);

        if (_prevCorridor == null)
        {
            firstRoom = true;
            xPos      = (int)(_column * 0.5f);
            yPos      = yPos = (int)(_height * 0.5f);

            prevCorridor = Direction.Size;
        }
        else
        {
            firstRoom = false;

            switch (_prevCorridor.direction)
            {
            case Direction.NORTH:
                xPos = _prevCorridor.EndPositionX - (roomWidth / 2);
                yPos = _prevCorridor.EndPositionY + 1;
                break;

            case Direction.EAST:
                xPos = _prevCorridor.EndPositionX + 1;
                yPos = _prevCorridor.EndPositionY - (roomHeight / 2);
                break;

            case Direction.SOUTH:
                xPos = _prevCorridor.EndPositionX - (roomWidth / 2);
                yPos = _prevCorridor.EndPositionY - roomHeight;
                break;

            case Direction.WEST:
                xPos = _prevCorridor.EndPositionX - roomWidth;
                yPos = _prevCorridor.EndPositionY - (roomHeight / 2);
                break;
            }
            _prevCorridor.connectedTo = true;
        }

        // room created successfully!
        generated = true;
    }
Пример #6
0
    public void InitNewLevel(int _floorNum, int _columns, int _rows, int _numRooms, int _gridSize, int _roomWidth, int _roomHeight, int _corridorLength)
    {
        columns    = _columns;
        rows       = _rows;
        m_FloorNum = _floorNum;

        // Set up Gameboard and Starting Room Coordinates
        m_StartingRoom = new CTRoomCoordinate(0, 0);

        int gameboardColum;

        gameboardColum   = _gridSize;
        m_StartingRoom.x = gameboardColum / 2;

        int gameboardRow;

        gameboardRow     = _gridSize;
        m_StartingRoom.y = gameboardRow / 2;

        //Debug.Log("ColumsSqrt: " + gameboardColum);
        //Debug.Log("RowsSqrt: " + gameboardRow);
        //Debug.Log("StartingRm: " + m_StartingRoom.x + ", " + m_StartingRoom.y);


        // Initialize GameBoard
        gameBoard = new bool[gameboardColum][];
        for (int i = 0; i < gameBoard.Length; ++i)
        {
            gameBoard[i] = new bool[gameboardRow];
        }


        SetupTilesArray();

        CreateRoomsAndCorridors(_numRooms, _roomWidth, _roomHeight, _corridorLength);

        SetTilesValuesForRooms();
        SetTilesValuesForCorridors();

        SetUpPathNodes();
        SetUpRoomDetector();
        SetUpStairs();

        m_isGenerated = true;
    }
Пример #7
0
    public Direction directionTo(CTRoomCoordinate _otherCoord)
    {
        Direction newDir = Direction.Size;
        int       diffX  = _otherCoord.x - x;
        int       diffY  = _otherCoord.y - y;

        if (diffY > 0)
        {
            if (newDir != Direction.Size)
            {
                return(Direction.Size);
            }
            newDir = Direction.NORTH;
        }

        if (diffY < 0)
        {
            if (newDir != Direction.Size)
            {
                return(Direction.Size);
            }
            newDir = Direction.SOUTH;
        }

        if (diffX > 0)
        {
            if (newDir != Direction.Size)
            {
                return(Direction.Size);
            }
            newDir = Direction.EAST;
        }

        if (diffX < 0)
        {
            if (newDir != Direction.Size)
            {
                return(Direction.Size);
            }
            newDir = Direction.WEST;
        }

        return(newDir);
    }
Пример #8
0
    public void Init(CTRoomCoordinate _spawnCoord)
    {
        m_RoomCoord = new CTRoomCoordinate(_spawnCoord);

        m_EnemyStats = new CStats();
        SetStatsByLevel(CTDungeon.Instance.currentFloor);
        m_IsImmortal  = false;
        m_EnemySprite = GetComponent <SpriteRenderer>().sprite;

        m_SM = new CStateMachine();
        m_SM.AddState(new CStateIdle(this.gameObject));
        m_SM.AddState(new CStatePatrol(this.gameObject));
        m_SM.AddState(new CStateChangeRoom(this.gameObject));
        m_SM.AddState(new CStateChaseRanged(this.gameObject));
        m_SM.AddState(new CStateAttackRanged(this.gameObject));
        m_SM.AddState(new CStateDead(this.gameObject));

        m_SM.SetNextState("StateIdle");
    }
Пример #9
0
    public void Init()
    {
        m_TargetList = new List <GameObject>();
        m_RoomCoord  = new CTRoomCoordinate(0, 0);

        m_EnemyStats = new CStats();
        SetStatsByLevel(CTDungeon.Instance.currentFloor);
        m_IsImmortal  = false;
        m_EnemySprite = GetComponent <SpriteRenderer>().sprite;

        m_SM = new CStateMachine();
        m_SM.AddState(new CStateIdle(this.gameObject));
        m_SM.AddState(new CStatePatrol(this.gameObject));
        m_SM.AddState(new CStateChangeRoom(this.gameObject));
        m_SM.AddState(new CStateChase(this.gameObject));
        m_SM.AddState(new CStateExplodeArmed(this.gameObject));
        m_SM.AddState(new CStateExplode(this.gameObject));
        m_SM.AddState(new CStateDead(this.gameObject));

        m_SM.SetNextState("StateIdle");
    }
Пример #10
0
    public void Init()
    {
        this.name         = "Player";
        m_PlayerStats     = new CStats();
        m_InventorySystem = new CInventorySystem(InventoryPanel.GetComponent <CInventorySlots>(), InventoryUI.GetComponent <CInventory>());
        m_playerQuestList = new List <QuestBase>();

        CProgression.Instance.LoadPlayerSave(this);

        m_RoomCoord = new CTRoomCoordinate(0, 0);

        PostOffice.Instance.Register(name, gameObject); // TODO Move to Spawn() ?

        m_IsImmortal   = false;
        m_PlayerSprite = GetComponent <SpriteRenderer>().sprite;

        m_PrestigeSystem = new PrestigeSystem();
        AchievementSystem.Instance.Init(this.GetStats());

        UIScript = GetComponent <PlayerUIScript>();
        UIScript.Init();
    }
Пример #11
0
    public void InitNewLevel(int _floorNum, int _columns, int _rows, int _numRooms, int _gridSize, int _roomWidth, int _roomHeight, int _corridorLength)
    {
        columns    = _columns;
        rows       = _rows;
        m_FloorNum = _floorNum;

        // Set up Gameboard and Starting Room Coordinates
        m_StartingRoom = new CTRoomCoordinate(0, 0);

        SetupTilesArray();

        CreateRoomsAndCorridors(_numRooms, _roomWidth, _roomHeight, _corridorLength);

        SetTilesValuesForRooms();
        SetTilesValuesForCorridors();

        SetUpRoomDetector();
        SetUpStairs();
        SetUpCheckpoint();

        m_isGenerated = true;
    }
Пример #12
0
    public void SetupCorridor(CTRoom _prevRoom, int length, Direction _direction)
    {
        direction = _direction;
        prevRoom  = _prevRoom;

        // Set a random length.
        corridorLength = length;

        switch (direction)
        {
        // If the choosen direction is NORTH (up)...
        case Direction.NORTH:
            // ... the starting position in the x axis can be random but within the width of the room.
            startXPos    = _prevRoom.xPos + (_prevRoom.roomWidth / 2);
            startYPos    = _prevRoom.yPos + _prevRoom.roomHeight;
            endRoomCoord = new CTRoomCoordinate(prevRoom.coordinate.x, prevRoom.coordinate.y + 1);
            break;

        case Direction.EAST:
            startXPos    = _prevRoom.xPos + _prevRoom.roomWidth;
            startYPos    = _prevRoom.yPos + _prevRoom.roomHeight / 2;
            endRoomCoord = new CTRoomCoordinate(prevRoom.coordinate.x + 1, prevRoom.coordinate.y);
            break;

        case Direction.SOUTH:
            startXPos    = _prevRoom.xPos + _prevRoom.roomWidth / 2;
            startYPos    = _prevRoom.yPos - 1;
            endRoomCoord = new CTRoomCoordinate(prevRoom.coordinate.x, prevRoom.coordinate.y - 1);
            break;

        case Direction.WEST:
            startXPos    = _prevRoom.xPos - 1;
            startYPos    = _prevRoom.yPos + _prevRoom.roomHeight / 2;
            endRoomCoord = new CTRoomCoordinate(prevRoom.coordinate.x - 1, prevRoom.coordinate.y);
            break;
        }
    }
Пример #13
0
 public CTRoomCoordinate(CTRoomCoordinate _mirror)
 {
     x = _mirror.x;
     y = _mirror.y;
 }
Пример #14
0
 public CPlayer()
 {
     m_RoomCoord = new CTRoomCoordinate(0, 0);
 }
Пример #15
0
    public Queue <CPathNode> BFS_ToRoom(CTRoomCoordinate _startRoom, CTRoomCoordinate _destRoom)
    {
        if (_startRoom.sameAs(_destRoom))
        {
            return(null);
        }

        CTFloor currFloor;

        if (floors[currentFloor] is CTFloor)
        {
            currFloor = floors[currentFloor] as CTFloor;
        }
        else
        {
            return(null);
        }

        bool[][] m_gameBoard = currFloor.gameBoard;
        int      boardColumn = m_gameBoard.Length;
        int      boardRow    = m_gameBoard[0].Length;

        bool[]             mVisited  = new bool[boardColumn * boardRow];
        CTRoomCoordinate[] mPrevious = new CTRoomCoordinate[boardColumn * boardRow];

        List <CTRoom>            mShortestPath = new List <CTRoom>();
        Queue <CTRoomCoordinate> mQueue        = new Queue <CTRoomCoordinate>();

        mQueue.Enqueue(_startRoom);

        while (mQueue.Count > 0)
        {
            CTRoomCoordinate curr = mQueue.Dequeue();
            if (curr.sameAs(_destRoom))
            {
                while (!curr.sameAs(_startRoom))
                {
                    mShortestPath.Insert(0, currFloor.GetRoomFromCoord(curr));
                    curr = mPrevious[curr.y * boardRow + curr.x];
                }
                mShortestPath.Insert(0, currFloor.GetRoomFromCoord(curr));
                break;
            }
            //Up
            if (curr.y < boardRow - 1)
            {
                CTRoomCoordinate next = new CTRoomCoordinate(curr.x, curr.y + 1);
                if (m_gameBoard[next.x][next.y])
                {
                    if (!mVisited[next.y * boardRow + next.x])
                    {
                        mPrevious[next.y * boardRow + next.x] = curr;
                        mQueue.Enqueue(next);
                        mVisited[next.y * boardRow + next.x] = true;
                    }
                }
            }
            //Down
            if (curr.y > 0)
            {
                CTRoomCoordinate next = new CTRoomCoordinate(curr.x, curr.y - 1);
                if (m_gameBoard[next.x][next.y])
                {
                    if (!mVisited[next.y * boardRow + next.x])
                    {
                        mPrevious[next.y * boardRow + next.x] = curr;
                        mQueue.Enqueue(next);
                        mVisited[next.y * boardRow + next.x] = true;
                    }
                }
            }
            //Right
            if (curr.x < boardColumn - 1)
            {
                CTRoomCoordinate next = new CTRoomCoordinate(curr.x + 1, curr.y);
                if (m_gameBoard[next.x][next.y])
                {
                    if (!mVisited[next.y * boardRow + next.x])
                    {
                        mPrevious[next.y * boardRow + next.x] = curr;
                        mQueue.Enqueue(next);
                        mVisited[next.y * boardRow + next.x] = true;
                    }
                }
            }
            //Up
            if (curr.x > 0)
            {
                CTRoomCoordinate next = new CTRoomCoordinate(curr.x - 1, curr.y);
                if (m_gameBoard[next.x][next.y])
                {
                    if (!mVisited[next.y * boardRow + next.x])
                    {
                        mPrevious[next.y * boardRow + next.x] = curr;
                        mQueue.Enqueue(next);
                        mVisited[next.y * boardRow + next.x] = true;
                    }
                }
            }
        }

        // No path found
        if (mShortestPath.Count <= 0)
        {
            return(null);
        }

        Queue <CPathNode> pathList = new Queue <CPathNode>();

        for (int i = 1; i < mShortestPath.Count; ++i)
        {
            CPathNode nextnode1;
            CPathNode nextnode2;

            switch (mShortestPath[i - 1].coordinate.directionTo(mShortestPath[i].coordinate))
            {
            case Direction.NORTH:
                nextnode1 = mShortestPath[i - 1].GetPathnode(PathNodeDir.NorthL);
                if (nextnode1 == null)
                {
                    return(pathList);
                }
                pathList.Enqueue(nextnode1);

                nextnode2 = mShortestPath[i].GetPathnode(PathNodeDir.SouthL);
                if (nextnode2 == null)
                {
                    return(pathList);
                }
                pathList.Enqueue(nextnode2);
                break;

            case Direction.SOUTH:
                nextnode1 = mShortestPath[i - 1].GetPathnode(PathNodeDir.SouthR);
                if (nextnode1 == null)
                {
                    return(pathList);
                }
                pathList.Enqueue(nextnode1);

                nextnode2 = mShortestPath[i].GetPathnode(PathNodeDir.NorthR);
                if (nextnode2 == null)
                {
                    return(pathList);
                }
                pathList.Enqueue(nextnode2);
                break;

            case Direction.EAST:
                nextnode1 = mShortestPath[i - 1].GetPathnode(PathNodeDir.EastU);
                if (nextnode1 == null)
                {
                    return(pathList);
                }
                pathList.Enqueue(nextnode1);

                nextnode2 = mShortestPath[i].GetPathnode(PathNodeDir.WestU);
                if (nextnode2 == null)
                {
                    return(pathList);
                }
                pathList.Enqueue(nextnode2);
                break;

            case Direction.WEST:
                nextnode1 = mShortestPath[i - 1].GetPathnode(PathNodeDir.WestD);
                if (nextnode1 == null)
                {
                    return(pathList);
                }
                pathList.Enqueue(nextnode1);

                nextnode2 = mShortestPath[i].GetPathnode(PathNodeDir.EastD);
                if (nextnode2 == null)
                {
                    return(pathList);
                }
                pathList.Enqueue(nextnode2);
                break;
            }
        }

        return(pathList);
    }
Пример #16
0
 public void Init(CTRoomCoordinate _coord)
 {
     m_roomCoord = _coord;
 }
Пример #17
0
 public bool sameAs(CTRoomCoordinate _otherCoord)
 {
     return(_otherCoord.x == this.x && _otherCoord.y == this.y);
 }
Пример #18
0
    public int SetupAllRoom(int _boardWidth, int _boardHeight, int _roomWidth, int _roomHeight, int _corridorLength, CTRoomCoordinate _startingCoord,
                            int _maxRooms, ref bool[][] _gameBoard, ref List <CTRoom> _rooms, ref List <CTCorridor> _corridors)
    {
        /*********************
        * GENERATE 1st ROOM
        *********************/
        firstRoom = true;

        // Set a random width and height.
        roomDepth  = 0;
        roomWidth  = _roomWidth;
        roomHeight = _roomHeight;

        xPos = (int)(_boardWidth * 0.5f - roomWidth * 0.5f);
        yPos = (int)(_boardHeight * 0.5f - roomHeight * 0.5f);

        coordinate = new CTRoomCoordinate(_startingCoord);
        _gameBoard[coordinate.x][coordinate.y] = true;

        //set up pathnodes
        //pathnodes.Add(new CPathNode(CenterPoint.x, yPos + roomHeight, Direction.NORTH, this));
        //pathnodes.Add(new CPathNode(xPos, CenterPoint.y, Direction.WEST, this));
        //pathnodes.Add(new CPathNode(CenterPoint.x, yPos, Direction.SOUTH, this));
        //pathnodes.Add(new CPathNode(xPos + roomWidth, CenterPoint.y + roomWidth, Direction.EAST, this));

        generated = true;
        int currNumRooms = 1;   // 1st room

        //Debug.Log("CR_Count " + _rooms.Count + "  _numRooms: " + currNumRooms);
        //Debug.Log("Coord: " + coordinate.x + ", " + coordinate.y );

        // Create Next Corridors and pathnodes
        for (int i = 0; i < (int)Direction.Size; ++i)
        {
            //Create Corridors
            // Safety Check  if not, create a corridor for the room
            switch ((Direction)i)
            {
            case Direction.NORTH:
                //if the next room will be out of board
                if (coordinate.y + 1 < _gameBoard[0].Length)
                {
                    if (!_gameBoard[coordinate.x][coordinate.y + 1])
                    {
                        break;
                    }
                }
                continue;

            case Direction.SOUTH:
                if (coordinate.y - 1 >= 0)
                {
                    if (!_gameBoard[coordinate.x][coordinate.y - 1])
                    {
                        break;
                    }
                }
                continue;

            case Direction.EAST:
                if (coordinate.x + 1 < _gameBoard.Length)
                {
                    if (!_gameBoard[coordinate.x + 1][coordinate.y])
                    {
                        break;
                    }
                }
                continue;

            case Direction.WEST:
                if (coordinate.x - 1 >= 0)
                {
                    if (!_gameBoard[coordinate.x - 1][coordinate.y])
                    {
                        break;
                    }
                }
                continue;
            }

            CTCorridor newCor = new CTCorridor();
            newCor.SetupCorridor(this, _corridorLength, (Direction)i);
            _corridors.Add(newCor);
            nextCorridors.Add((Direction)i, newCor);
        }

        int availableRooms = nextCorridors.Count;

        // Create Next Room
        CTRoomCoordinate nextRoomCoord = new CTRoomCoordinate(0, 0);

        foreach (Direction nextdir in nextCorridors.Keys)
        {
            //if direction have a room alrdy base on the _gameboard, skip
            //if direction is same as previous corridor / corridors in list, skip
            //random a corridor except for north side and check if they got slot on gameboard
            switch (nextdir)
            {
            case Direction.NORTH:
                if (!_gameBoard[coordinate.x][coordinate.y + 1])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x, coordinate.y + 1);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_roomWidth, _roomHeight, nextRoomCoord, nextCorridors[nextdir], ref currNumRooms, ref availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, 0);
                }
                break;

            case Direction.EAST:
                if (!_gameBoard[coordinate.x + 1][coordinate.y])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x + 1, coordinate.y);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_roomWidth, _roomHeight, nextRoomCoord, nextCorridors[nextdir], ref currNumRooms, ref availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, 0);
                }
                break;

            case Direction.WEST:
                if (!_gameBoard[coordinate.x - 1][coordinate.y])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x - 1, coordinate.y);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_roomWidth, _roomHeight, nextRoomCoord, nextCorridors[nextdir], ref currNumRooms, ref availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, 0);
                }
                break;

            case Direction.SOUTH:
                if (!_gameBoard[coordinate.x][coordinate.y - 1])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x, coordinate.y - 1);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_roomWidth, _roomHeight, nextRoomCoord, nextCorridors[nextdir], ref currNumRooms, ref availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, 0);
                }
                break;
            }
        }

        //Check if its enough rooms
        while (currNumRooms < _maxRooms)
        {
            CreateEndRooms(_roomWidth, _roomHeight, _corridorLength, GetEndRooms(_rooms, _maxRooms / 4), ref currNumRooms, ref availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors);
        }

        return(currNumRooms);
    }
Пример #19
0
    private void SetupEndRoom(int _width, int _height, int _corridorLength,
                              ref int _numRooms, ref int _availableRooms, ref int _maxRooms, ref bool[][] _gameBoard, ref List <CTRoom> _rooms, ref List <CTCorridor> _corridors)
    {
        //Safety measures
        if (nextCorridors.Count > 0)
        {
            return;
        }

        //Create Corridors
        GameObject node;
        int        startDir = Random.Range(0, (int)Direction.Size);

        for (int i = 0; i < (int)Direction.Size; ++i, ++startDir)
        {
            Direction nextDir = (Direction)(startDir % (int)Direction.Size);
            //if ((startDir % (int)Direction.Size) != (int)prevCorridor)
            {
                //Create Corridors
                if (Random.Range(0.0f, 1.0f) <= 0.5f - i * 0.1f)
                {
                    // Safety Check  if not, create a corridor for the room
                    switch (nextDir)
                    {
                    case Direction.NORTH:
                        if (coordinate.y + 1 < _gameBoard[0].Length)
                        {
                            if (!_gameBoard[coordinate.x][coordinate.y + 1])
                            {
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(CenterPoint.x - 1, yPos + roomHeight - 1, PathNodeDir.NorthL, this);
                                pathnodes.Add(PathNodeDir.NorthL, node.GetComponent <CPathNode>());
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(CenterPoint.x + 1, yPos + roomHeight - 1, PathNodeDir.NorthR, this);
                                pathnodes.Add(PathNodeDir.NorthR, node.GetComponent <CPathNode>());
                                break;
                            }
                        }
                        continue;

                    case Direction.SOUTH:
                        if (coordinate.y - 1 >= 0)
                        {
                            if (!_gameBoard[coordinate.x][coordinate.y - 1])
                            {
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(CenterPoint.x - 1, yPos, PathNodeDir.SouthL, this);
                                pathnodes.Add(PathNodeDir.SouthL, node.GetComponent <CPathNode>());
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(CenterPoint.x + 1, yPos, PathNodeDir.SouthR, this);
                                pathnodes.Add(PathNodeDir.SouthR, node.GetComponent <CPathNode>());
                                break;
                            }
                        }
                        continue;

                    case Direction.EAST:
                        if (coordinate.x + 1 < _gameBoard.Length)
                        {
                            if (!_gameBoard[coordinate.x + 1][coordinate.y])
                            {
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(xPos + roomWidth - 1, CenterPoint.y - 1, PathNodeDir.EastD, this);
                                pathnodes.Add(PathNodeDir.EastD, node.GetComponent <CPathNode>());
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(xPos + roomWidth - 1, CenterPoint.y + 1, PathNodeDir.EastU, this);
                                pathnodes.Add(PathNodeDir.EastU, node.GetComponent <CPathNode>());
                                break;
                            }
                        }
                        continue;

                    case Direction.WEST:
                        if (coordinate.x - 1 >= 0)
                        {
                            if (!_gameBoard[coordinate.x - 1][coordinate.y])
                            {
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(xPos, CenterPoint.y - 1, PathNodeDir.WestD, this);
                                pathnodes.Add(PathNodeDir.WestD, node.GetComponent <CPathNode>());
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(xPos, CenterPoint.y + 1, PathNodeDir.WestU, this);
                                pathnodes.Add(PathNodeDir.WestU, node.GetComponent <CPathNode>());
                                break;
                            }
                        }
                        continue;
                    }

                    CTCorridor newCor = new CTCorridor();
                    newCor.SetupCorridor(this, _corridorLength, nextDir);
                    _corridors.Add(newCor);
                    nextCorridors.Add(nextDir, newCor);
                }
            }
        }

        // Create 1 End Room
        if (nextCorridors.Count <= 0)
        {
            return;
        }

        _availableRooms += nextCorridors.Count;

        // Create Next Room
        CTRoomCoordinate nextRoomCoord = new CTRoomCoordinate(0, 0);

        foreach (Direction nextdir in nextCorridors.Keys)
        {
            //if direction have a room alrdy base on the _gameboard, skip
            switch (nextdir)
            {
            case Direction.NORTH:
                if (!_gameBoard[coordinate.x][coordinate.y + 1])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x, coordinate.y + 1);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth, true);
                }
                break;

            case Direction.EAST:
                if (!_gameBoard[coordinate.x + 1][coordinate.y])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x + 1, coordinate.y);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth, true);
                }
                break;

            case Direction.WEST:
                if (!_gameBoard[coordinate.x - 1][coordinate.y])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x - 1, coordinate.y);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth, true);
                }
                break;

            case Direction.SOUTH:
                if (!_gameBoard[coordinate.x][coordinate.y - 1])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x, coordinate.y - 1);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth, true);
                }
                break;
            }
        }
    }
Пример #20
0
    private void SetupRoom(int _width, int _height, CTRoomCoordinate _roomCoordinate, CTCorridor _prevCorridor,
                           ref int _numRooms, ref int _availableRooms, ref int _maxRooms, ref bool[][] _gameBoard, ref List <CTRoom> _rooms, ref List <CTCorridor> _corridors,
                           int _depth, bool _ignoreDepth = false)
    {
        //Return Mechanic / Safety
        if (_roomCoordinate.x >= _gameBoard.Length)
        {
            return;
        }

        if (_roomCoordinate.y >= _gameBoard[0].Length)
        {
            return;
        }

        if (_gameBoard[_roomCoordinate.x][_roomCoordinate.y])
        {
            return;
        }

        // Init Values
        // Set the entering corridor direction.
        nextCorridors = new Dictionary <Direction, CTCorridor>();
        prevCorridor  = _prevCorridor.direction;

        roomWidth  = _width;
        roomHeight = _height;
        roomDepth  = _depth + 1;

        coordinate = new CTRoomCoordinate(_roomCoordinate);

        //set up pathnodes
        pathnodes = new Dictionary <PathNodeDir, CPathNode>();

        //Create Room
        switch (_prevCorridor.direction)
        {
        // If the corridor entering this room is going north...
        case Direction.NORTH:
            // The y coordinate of the room must be at the end of the corridor (since the corridor leads to the bottom of the room).
            xPos = _prevCorridor.EndPositionX - (roomWidth / 2);
            yPos = _prevCorridor.EndPositionY + 1;
            break;

        case Direction.EAST:
            xPos = _prevCorridor.EndPositionX + 1;
            yPos = _prevCorridor.EndPositionY - (roomHeight / 2);
            break;

        case Direction.SOUTH:
            xPos = _prevCorridor.EndPositionX - (roomWidth / 2);
            yPos = _prevCorridor.EndPositionY - roomHeight;
            break;

        case Direction.WEST:
            xPos = _prevCorridor.EndPositionX - roomWidth;
            yPos = _prevCorridor.EndPositionY - (roomHeight / 2);
            break;
        }

        // room created successfully!
        _prevCorridor.connectedTo = true;
        generated = true;
        _gameBoard[_roomCoordinate.x][_roomCoordinate.y] = true;

        //pathnodes.Add(new CPathNode(CenterPoint.x, yPos + roomHeight, Direction.NORTH, this));
        //pathnodes.Add(new CPathNode(xPos, CenterPoint.y, Direction.WEST, this));
        //pathnodes.Add(new CPathNode(CenterPoint.x, yPos, Direction.SOUTH, this));
        //pathnodes.Add(new CPathNode(xPos + roomWidth, CenterPoint.y + roomWidth, Direction.EAST, this));

        _availableRooms--;
        _numRooms++;
        //Debug.Log("CR_Count " + _rooms.Count + "  _numRooms: " + _numRooms);
        //Debug.Log("Coord: " + coordinate.x + ", " + coordinate.y);

        if (_numRooms >= _maxRooms)
        {
            return;
        }

        int limit = _maxRooms / 4;

        if (limit < _depth && !_ignoreDepth)
        {
            return;
        }

        // Create Next Corridors and Pathnode
        int startDir = Random.Range(0, (int)Direction.Size);

        for (int i = 0; i < (int)Direction.Size; ++i, ++startDir)
        {
            Direction nextDir = (Direction)(startDir % (int)Direction.Size);
            //Create Corridors
            if (Random.Range(0.0f, 1.0f) <= 1.0f - (_numRooms + _availableRooms) / _maxRooms - i * 0.1f)
            {
                // Safety Check  if not, create a corridor for the room
                switch (nextDir)
                {
                case Direction.NORTH:
                    //if the next room will be out of board
                    if (coordinate.y + 1 < _gameBoard[0].Length)
                    {
                        if (!_gameBoard[coordinate.x][coordinate.y + 1])
                        {
                            break;
                        }
                    }
                    continue;

                case Direction.SOUTH:
                    if (coordinate.y - 1 >= 0)
                    {
                        if (!_gameBoard[coordinate.x][coordinate.y - 1])
                        {
                            break;
                        }
                    }
                    continue;

                case Direction.EAST:
                    if (coordinate.x + 1 < _gameBoard.Length)
                    {
                        if (!_gameBoard[coordinate.x + 1][coordinate.y])
                        {
                            break;
                        }
                    }
                    continue;

                case Direction.WEST:
                    if (coordinate.x - 1 >= 0)
                    {
                        if (!_gameBoard[coordinate.x - 1][coordinate.y])
                        {
                            break;
                        }
                    }
                    continue;
                }

                CTCorridor newCor = new CTCorridor();
                newCor.SetupCorridor(this, _prevCorridor.corridorLength, nextDir);
                _corridors.Add(newCor);
                nextCorridors.Add(nextDir, newCor);
            }
        }

        // Create 1 End Room
        if (nextCorridors.Count <= 0)
        {
            return;
        }

        _availableRooms += nextCorridors.Count;

        // Create Next Room
        CTRoomCoordinate nextRoomCoord = new CTRoomCoordinate(0, 0);

        foreach (Direction nextdir in nextCorridors.Keys)
        {
            //if direction have a room alrdy base on the _gameboard, skip
            switch (nextdir)
            {
            case Direction.NORTH:
                if (!_gameBoard[coordinate.x][coordinate.y + 1])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x, coordinate.y + 1);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth);
                }
                break;

            case Direction.EAST:
                if (!_gameBoard[coordinate.x + 1][coordinate.y])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x + 1, coordinate.y);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth);
                }
                break;

            case Direction.WEST:
                if (!_gameBoard[coordinate.x - 1][coordinate.y])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x - 1, coordinate.y);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth);
                }
                break;

            case Direction.SOUTH:
                if (!_gameBoard[coordinate.x][coordinate.y - 1])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x, coordinate.y - 1);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth);
                }
                break;
            }
        }
    }
Пример #21
0
 public CTRoom GetRoomFromCoord(CTRoomCoordinate _coord)
 {
     return(null);
 }