private void GetLevel()
    {
        levelData = levelGenerator.BuildLevelData();
        grid      = levelData.data;

        rootNode = null;

        while (rootNode == null)
        {
            rootNode = grid.GetNode(ExtensionMethods.ToEvenGridPosition(Random.Range(0, grid.Width), 1), ExtensionMethods.ToEvenGridPosition(Random.Range(0, grid.Height), 1));
            if (rootNode.Data != NodeState.Empty)
            {
                rootNode = null;
            }
        }

        print(rootNode.position.x + " " + rootNode.position.y);

        BuildPath(ref grid, rootNode, 0);

        PlaceDoors();

        rootNode.Reduce(ref grid, NodeState.Door, NodeState.Empty);

        SetBlocks();
        //InitDebugTexture();

        OnComplete.Invoke();
    }
    void SetBlocks()
    {
        if (grid != null)
        {
            for (int y = 0; y < grid.Height; y++)
            {
                for (int x = 0; x < grid.Width; x++)
                {
                    if (grid.GetNode(x, y).Data == NodeState.Room || grid.GetNode(x, y).Data == NodeState.Path || grid.GetNode(x, y).Data == NodeState.Door)
                    {
                        world.SetBlock(x + worldXOffset, 2, y + worldYOffset, new BlockAir());
                    }

                    if (grid.GetNode(x, y).Data == NodeState.Empty)
                    {
                        world.SetBlock(x + worldXOffset, 0, y + worldYOffset, new BlockAir());
                        world.SetBlock(x + worldXOffset, 1, y + worldYOffset, new BlockAir());
                        world.SetBlock(x + worldXOffset, 2, y + worldYOffset, new BlockAir());
                    }
                }
            }
        }
        List <TileNode <NodeState> > nodes = new List <TileNode <NodeState> >();

        //rootNode.GetConnections(ref nodes);
        print(nodes.Count);
        //for (int i = 0; i < nodes.Count; i++)
        //{
        //    world.SetBlock((nodes[i].x), 2, nodes[i].y, new BlockAir());
        //}
    }
Exemple #3
0
 private void FixedUpdate()
 {
     m_start = m_grid.GetNode(m_startPoint);
     m_end   = m_grid.GetNode(m_endPoint);
 }
 public GridNode GetNeighbour(int in_x, int in_y)
 {
     return(m_grid.GetNode(x + in_x, y + in_y));
 }