Esempio n. 1
0
    public void SetPushTargets(Vector2 cell, int qty)
    {
        int i    = qty < 0 ? -1 : 1;
        int incr = qty < 0 ? -1 : 1;

        if (cell.x - x > cell.y - y && (cell.x - x) + (cell.y - y) >= 0) // Front
        {
            while (i != qty + incr)
            {
                CellBehaviour cellBehaviour = grid.GetCellBehaviour(x - i, y);
                if (cellBehaviour == null ||
                    !cellBehaviour.isWalkable ||
                    grid.GetEntityOnCell(x - i, y) != null)
                {
                    break;
                }
                pushTargets.Add(new Vector2(x - i, y));
                i += qty < 0 ? -1 : 1;
            }
        }
        else if (cell.x - x >= cell.y - y && (cell.x - x) + (cell.y - y) < 0) // Left
        {
            while (i != qty + incr)
            {
                CellBehaviour cellBehaviour = grid.GetCellBehaviour(x, y + i);
                if (cellBehaviour == null || !cellBehaviour.isWalkable ||
                    grid.GetEntityOnCell(x, y + i) != null)
                {
                    break;
                }
                pushTargets.Add(new Vector2(x, y + i));
                i += qty < 0 ? -1 : 1;
            }
        }
        else if (cell.x - x < cell.y - y && (cell.x - x) + (cell.y - y) <= 0) // Back
        {
            while (i != qty + incr)
            {
                CellBehaviour cellBehaviour = grid.GetCellBehaviour(x + i, y);
                if (cellBehaviour == null ||
                    !cellBehaviour.isWalkable ||
                    grid.GetEntityOnCell(x + i, y) != null)
                {
                    break;
                }
                pushTargets.Add(new Vector2(x + i, y));
                i += qty < 0 ? -1 : 1;
            }
        }
        else if (cell.x - x <= cell.y - y && (cell.x - x) + (cell.y - y) > 0) // Right
        {
            while (i != qty + incr)
            {
                CellBehaviour cellBehaviour = grid.GetCellBehaviour(x, y - i);
                if (cellBehaviour == null ||
                    !cellBehaviour.isWalkable ||
                    grid.GetEntityOnCell(x, y - i) != null)
                {
                    break;
                }
                pushTargets.Add(new Vector2(x, y - i));
                i += qty < 0 ? -1 : 1;
            }
        }
    }