예제 #1
0
    /// <summary>
    /// Recursivly follows the drawpath instructions in order to render the tiles
    /// </summary>
    /// <param name="dpi"></param>
    /// <param name="oldPosition"></param>
    /// <param name="oldNode"></param>
    private void HandleDPI(DrawPathInstruction dpi, Vector2Int oldPosition, Node oldNode, bool grayout)
    {
        //If our map does not have a node in the instruction dir, we cannot render in that dir
        //if (oldNode.GetConnectionFromDir(dpi.dir) == null) {
        if (oldNode[(int)dpi.dir] < 0)                  // if this does not point to a node
        {
            return;
        }

        Vector2Int position = oldPosition + dpi.dir.offset();
        RenderTile tile     = renderLayers[dpi.dir.renderLayer()][position.x, position.y];

        grayout = grayout || GameManager.gameplay.map.disjoint(oldNode, dpi.dir);               // gray-out if disjoint, or previos node was grayed-out
        Node node = GameManager.gameplay.map[oldNode[(int)dpi.dir]];

        //Draw the node, regarless of if it is null (null node is handled by the drawer)
        tile.DrawFullNode(node, dpi.dir, position, grayout);
        //If the node is not null, then we continue on with the instructions
        if (node != null)
        {
            //Add it to the list of drawn nodes
            if (visibleNodes.Contains(node) == false)
            {
                visibleNodes.Add(node);
            }
            //Follow instructions on the next node
            foreach (DrawPathInstruction nDpi in dpi.nextInstructions)
            {
                HandleDPI(nDpi, position, node, grayout);
            }
        }
    }
예제 #2
0
    private void HandleDPI(DrawPathInstruction dpi, Vector2Int oldPosition, Node oldNode)
    {
        //If our map does not have a node in the instruction dir, we cannot render in that dir
        if (oldNode.GetConnectionFromDir(dpi.dir) == null)
        {
            return;
        }

        Vector2Int position = oldPosition + dpi.dir.offset();
        RenderTile tile     = renderLayers[dpi.dir.renderLayer()][position.x, position.y];
        Node       node     = GameManager.instance.map[(int)oldNode.GetConnectionFromDir(dpi.dir)];

        //Draw the node, regarless of if it is null (null node is handled by the drawer)
        tile.DrawFullNode(node);
        //If the node is not null, then we continue on with the instructions
        if (node != null)
        {
            //Add it to the list of drawn nodes
            if (visibleNodes.Contains(node) == false)
            {
                visibleNodes.Add(node);
            }
            //Follow instructions on the next node
            foreach (DrawPathInstruction nDpi in dpi.nextInstructions)
            {
                HandleDPI(nDpi, position, node);
            }
        }
    }
예제 #3
0
    void Start()
    {
        center = new Vector2Int(renderMap.dim / 2, renderMap.dim / 2);

        drawPathInstructions = new DrawPathInstruction[4];
        for (int i = 0; i < 4; i++)
        {
            Direction dir   = (Direction)i;
            Direction left  = dir.counterclockwise();
            Direction right = dir.clockwise();
            drawPathInstructions[i] = new DrawPathInstruction(dir, new DrawPathInstruction[] {
                new DrawPathInstruction(dir, new DrawPathInstruction[] { new DrawPathInstruction(left, new DrawPathInstruction[] { }), new DrawPathInstruction(right, new DrawPathInstruction[] { }) }),
                new DrawPathInstruction(left, new DrawPathInstruction[] { new DrawPathInstruction(dir, new DrawPathInstruction[] { new DrawPathInstruction(left, new DrawPathInstruction[] { }) }) }),
                new DrawPathInstruction(right, new DrawPathInstruction[] { new DrawPathInstruction(dir, new DrawPathInstruction[] { new DrawPathInstruction(right, new DrawPathInstruction[] { }) }) }),
            });
        }
    }
예제 #4
0
    // Use this for initialization
    public void initialize()
    {
        center = new Vector2Int(renderMap.dim / 2, renderMap.dim / 2);

        // drawPathInstructions does need to be hardcoded, but this algorithm makes it so only 1/4 of it needs to be written, since it is the same pattern in each of the 4 directions
        if (drawPathInstructions.Length < 4)
        {
            drawPathInstructions = new DrawPathInstruction[4];
            for (int i = 0; i < 4; i++)
            {
                Direction dir   = (Direction)i;
                Direction left  = dir.counterclockwise();
                Direction right = dir.clockwise();
                drawPathInstructions[i] = new DrawPathInstruction(dir, new DrawPathInstruction[] {
                    new DrawPathInstruction(dir, new DrawPathInstruction[] { new DrawPathInstruction(left, new DrawPathInstruction[] { }), new DrawPathInstruction(right, new DrawPathInstruction[] { }) }),
                    new DrawPathInstruction(left, new DrawPathInstruction[] { new DrawPathInstruction(dir, new DrawPathInstruction[] { new DrawPathInstruction(left, new DrawPathInstruction[] { }) }) }),
                    new DrawPathInstruction(right, new DrawPathInstruction[] { new DrawPathInstruction(dir, new DrawPathInstruction[] { new DrawPathInstruction(right, new DrawPathInstruction[] { }) }) }),
                });
            }
        }
    }