Exemple #1
0
    private void CreateRoom(FloorNode node, bool isNeighbour)
    {
        //add the node to the list of shown rooms
        shownNodes.Add(node);

        //create a room on the minimap
        GameObject room = GameObject.Instantiate(mapRoom, panel.transform);

        room.transform.position  = room.transform.parent.position;
        room.transform.position += new Vector3(node.GetCoord().x * 60, node.GetCoord().y * 20, 0);

        //handle the icon of specific rooms
        FloorNode.roomTypeEnum roomType = node.GetRoomType();

        switch (roomType)
        {
        case FloorNode.roomTypeEnum.sellerRoom:
            room.transform.GetChild(0).GetComponent <Image>().sprite = iconSeller;
            break;

        case FloorNode.roomTypeEnum.bossRoom:
        case FloorNode.roomTypeEnum.miniBossRoom:
            room.transform.GetChild(0).GetComponent <Image>().sprite = iconBoss;
            break;

        case FloorNode.roomTypeEnum.exitRoom:
            room.transform.GetChild(0).GetComponent <Image>().sprite = iconExit;
            break;

        case FloorNode.roomTypeEnum.itemRoom:
            room.transform.GetChild(0).GetComponent <Image>().sprite = iconItem;
            break;

        default:
            Destroy(room.transform.GetChild(0).gameObject);
            break;
        }

        displayedRooms.Add(room);

        if (isNeighbour)
        {
            SetRoomTransparency(room, 0.3f);
        }
    }
Exemple #2
0
    private void CreateRandomNode(FloorNode.roomTypeEnum roomType)
    {
        bool canBeCreated = false;

        //debug count
        int count = 0;

        while (!canBeCreated && count < 1000)
        {
            count++;

            //take an existing room
            FloorNode existingNode = nodeList[Random.Range(0, nodeList.Count)];

            //choose a random direction
            var randomDirection = (FloorNode.directionEnum)Random.Range(0, 4);

            //set the new room coord based on the existing room we used to place it
            (int x, int y) = existingNode.GetCoord();

            if (randomDirection == FloorNode.directionEnum.east)
            {
                x += 1;
            }
            if (randomDirection == FloorNode.directionEnum.west)
            {
                x -= 1;
            }
            if (randomDirection == FloorNode.directionEnum.north)
            {
                y += 1;
            }
            if (randomDirection == FloorNode.directionEnum.south)
            {
                y -= 1;
            }

            //if the existing room is a regular room, is not occupied, has no room at the direction chosen
            //and does not exceed one of the maximum coordinate, we create the room there
            if (existingNode.GetNeighbourNode(randomDirection) == null &&
                !isTileOccupied(x, y) &&
                existingNode.GetRoomType() == FloorNode.roomTypeEnum.regular &&
                x < 4 && x > -4 && y < 4 && y > -4)
            {
                FloorNode newNode = new FloorNode();

                newNode.SetRoomType(roomType);

                //connect the new room with the existing room
                CreateLinkBetweenNodes(existingNode, newNode, randomDirection);

                newNode.SetCoord(x, y);

                if (existingNode.GetRoomType() == FloorNode.roomTypeEnum.regular)
                {
                    //check if there are rooms existing around the new room and connect them.
                    //This allow the level to have loops and not look like a tree
                    ConnectNodeNeighbours(newNode);
                }

                nodeList.Add(newNode);
                canBeCreated = true;
            }
        }
    }