Exemple #1
0
    // check if all child elements can exist one grid step in some direction
    public bool IsOneGridStepThereCollisional(Vector3 gridDirThere, WorldGridManager worldGridManager)
    {
        RecalculateChildElementGridPositions();

        Vector3 checkedGridPosition;

        for (int i = 0; i < childElements.Length; i++)
        {
            // one grid step in specified direction
            checkedGridPosition =
                childElements[i].GetGridPosition() + gridDirThere;

            // is there something?
            if (worldGridManager.IsThisGridCellOccupied(checkedGridPosition))
            {
                return(true);
            }

            // or is it out of boundaries?
            if (childElements[i].GetGridPosX() + gridDirThere.x < 0 - ((Design.gridWidth - 1) / 2) - 1 ||
                childElements[i].GetGridPosX() + gridDirThere.x > 0 + ((Design.gridWidth - 1) / 2) + 1)
            {
                return(true);
            }
        }

        // all block child elements are in that one-step-up position without collision
        return(false);
    }
Exemple #2
0
    // game mechanics of a block

    // check if all child elements can exist where they are in a grid
    public bool IsGridPosCollisional(WorldGridManager worldGridManager)
    {
        RecalculateChildElementGridPositions();

        for (int i = 0; i < childElements.Length; i++)
        {
            // is there something?
            if (worldGridManager.IsThisGridCellOccupied(childElements[i].GetGridPosition()))
            {
                return(true);
            }
        }

        return(false);
    }
Exemple #3
0
    public int UpmostLandingGridDistance(WorldGridManager worldGridManager)
    {
        RecalculateChildElementGridPositions();

        Vector3 checkedGridPosition;

        for (int x = 0; x < Design.gridInfinityAhead; x++)
        {
            for (int i = 0; i < childElements.Length; i++)
            {
                // xth + 1 grid step up
                checkedGridPosition =
                    childElements[i].GetGridPosition() + new Vector3(0, x + 1, 0);

                // is there something?
                if (worldGridManager.IsThisGridCellOccupied(checkedGridPosition))
                {
                    return(x);
                }
            }
        }

        return(0);
    }
Exemple #4
0
 private void Awake()
 {
     unit      = GetComponent <Unit>();
     worldGrid = GameObject.FindGameObjectWithTag("Scripts").GetComponent <WorldGridManager>();
 }
Exemple #5
0
 private void Start()
 {
     worldGrid = GetComponent <WorldGridManager>();
 }