Exemplo n.º 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);
        }
    }
Exemplo n.º 2
0
    public void ConnectNodeNeighbours(FloorNode baseNode)
    {
        //connect rooms only if they are regular rooms
        if (baseNode.GetRoomType() == FloorNode.roomTypeEnum.regular)
        {
            //look if there are rooms neighbouring the base node, and if there are, connect them to the base node
            foreach (FloorNode node in nodeList)
            {
                //connect the regular room only to other regular rooms
                if (node.GetRoomType() == FloorNode.roomTypeEnum.regular)
                {
                    FloorNode.directionEnum direction;

                    if (node.GetCoord().x == baseNode.GetCoord().x + 1 && node.GetCoord().y == baseNode.GetCoord().y)
                    {
                        direction = FloorNode.directionEnum.east;
                        CreateLinkBetweenNodes(baseNode, node, direction);
                    }

                    if (node.GetCoord().x == baseNode.GetCoord().x - 1 && node.GetCoord().y == baseNode.GetCoord().y)
                    {
                        direction = FloorNode.directionEnum.west;
                        CreateLinkBetweenNodes(baseNode, node, direction);
                    }

                    if (node.GetCoord().x == baseNode.GetCoord().x&& node.GetCoord().y == baseNode.GetCoord().y + 1)
                    {
                        direction = FloorNode.directionEnum.north;
                        CreateLinkBetweenNodes(baseNode, node, direction);
                    }

                    if (node.GetCoord().x == baseNode.GetCoord().x&& node.GetCoord().y == baseNode.GetCoord().y - 1)
                    {
                        direction = FloorNode.directionEnum.south;
                        CreateLinkBetweenNodes(baseNode, node, direction);
                    }
                }
            }
        }
    }
Exemplo n.º 3
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;
            }
        }
    }