コード例 #1
0
    private Vector2i FindNearestInList(Vector2i pos)
    {
        roomList.Remove(roomList[0]);
        GeneratorRoom nearestRoom = null;
        float         nearestDist = 100f;

        if (roomList.Count < 1)
        {
            return(grid.RoomList[0].location);
        }

        else
        {
            for (int i = 0; i < roomList.Count; i++)
            {
                if (roomList[i].location.DistTo(pos) < nearestDist)
                {
                    nearestDist = roomList[i].location.DistTo(pos);
                    nearestRoom = roomList[i];
                }
            }
        }
        if (nearestRoom != null)
        {
            return(nearestRoom.location);
        }
        else
        {
            Debug.LogError("Possible bug with Walls");
            return(Vector2i.zero);
        }
    }
コード例 #2
0
ファイル: GeneratorGrid.cs プロジェクト: Halloweens/RogueRpg
    public GeneratorRoom CreateRoom(Vector2i chunkPos, GeneratorChunk groundPrefab, Vector2i roomSize, bool isSecure = false)
    {
        GeneratorRoom newRoom = new GeneratorRoom();
        GameObject    room    = new GameObject();

        room.transform.SetParent(parent.transform);
        Color testColor = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), 1.0f);

        room.name = "Room";

        for (int i = 0; i < roomSize.y; i++)
        {
            for (int j = 0; j < roomSize.x; j++)
            {
                GeneratorChunk c = CreateChunk(chunkPos + new Vector2i(j, i), groundPrefab, testColor, room);
                newRoom.chunks.Add(c);
            }
        }

        if (isSecure)
        {
            newRoom.isSafe = true;
            room.name      = "SecureRoom";
            safeRoomList.Add(newRoom);
        }
        else
        {
            unSafeRoomList.Add(newRoom);
        }

        newRoom.location = chunkPos;
        newRoom.size     = roomSize;

        roomList.Add(newRoom);

        return(newRoom);
    }