Ejemplo n.º 1
0
    public void Setup(int w, int h)
    {
        width             = w;
        height            = h;
        roomBounds.width  = width * gridInfo.tileSize;
        roomBounds.height = height * gridInfo.tileSize;
        GridPos p = new GridPos(0, 0); //used for iteration and placement

        sprites = new SpriteRenderer[width * height];
        GameObject obj; //reference for current tile object

        while (p.y < height)
        {
            while (p.x < width)
            {
                obj = new GameObject("Tile");
                obj.transform.SetParent(transform);
                obj.transform.position     = gridInfo.GetGridVector(p);
                sprites[p.GetIndex(width)] = obj.AddComponent <SpriteRenderer>();
                sprites[p.GetIndex(width)].sortingLayerID = spriteLayerId;
                p.x++;
            }
            p.y++;
            p.x = 0;
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Function called to update grid for a new room
    /// </summary>
    public void UpdateGrid()
    {
        room = GameController.Main.currentRoom;

        //For every point on the grid x axis...
        for (int x = 0; x < gridSizeX; x++)
        {
            //for every point on the grids y axis...
            for (int y = 0; y < gridSizeY; y++)
            {
                //Sets the position of the node
                grid[x, y].worldPosition = gridTransform.GetGridVector(new GridPos(x, y));
                //Determines if hte node is walkable
                grid[x, y].walkable = room.GetValue(x, y, Layer.Collision) == 0 && room.GetValue(x, y, Layer.Other) != 2 &&
                                      room.GetValue(x, y, Layer.Other) != NOMOVEU &&
                                      room.GetValue(x, y, Layer.Other) != NOMOVED &&
                                      room.GetValue(x, y, Layer.Other) != NOMOVEL &&
                                      room.GetValue(x, y, Layer.Other) != NOMOVER; //2 = door
            }
        }
    }