Exemplo n.º 1
0
    private void Start()
    {
        TileBuilderWrapper tbw = TileGeneration.buildTiles();

        allTiles      = tbw.allTiles;
        outgoingEdges = tbw.outgoingEdges;
        incomingTiles = tbw.incomingTiles;

        // We only need to draw the ground once
        this.tileDraw.drawGround(allTiles);
    }
Exemplo n.º 2
0
    // TODO: Make distance a float based on distance. Currently it's just int of weight 1 => might not play nice with A* huristic
    public static TileBuilderWrapper buildTiles()
    {
        // NOTE: Result is accessed via (x,y)

        TileBuilderWrapper result = new TileBuilderWrapper();

        // Add the top row of tiles
        for (int x = 0; x < GameSetup.BOARD_WIDTH; x++)
        {
            Tile t = new Tile(new Vector2Int(x, 0));
            result.addTile(x, 0, t);
        }

        // Add the leftmost col of tiles
        // NOTE [0,0] has already been made, start at [0,1]
        for (int y = 1; y < GameSetup.BOARD_HEIGHT; y++)
        {
            Tile t          = new Tile(new Vector2Int(0, y));
            Tile upNeighbor = result.allTiles[0, y - 1];

            result.addTile(0, y, t);

            // Add a double ended edge from (t <-> upNeighbor) with weight of 1
            result.addTwoWayNeighbor(t, upNeighbor, Vector2.Distance(t.position, upNeighbor.position));
        }

        // Add all the remaining tiles
        // NOTE: start at 1,1
        for (int y = 1; y < GameSetup.BOARD_HEIGHT; y++)
        {
            for (int x = 1; x < GameSetup.BOARD_WIDTH; x++)
            {
                Tile t = new Tile(new Vector2Int(x, y));

                result.addTile(x, y, t);

                // Because we initialized the top row and left col
                // we are guarenteed that these operations are NOT out of bounds
                Tile leftNeighbor = result.allTiles[x - 1, y];
                Tile upNeighbor   = result.allTiles[x, y - 1];

                result.addTwoWayNeighbor(t, leftNeighbor, Vector2.Distance(t.position, upNeighbor.position));
                result.addTwoWayNeighbor(t, upNeighbor, Vector2.Distance(t.position, upNeighbor.position));
            } // End x loop
        }     // End Y loop

        return(result);
    }