// 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); }
// 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); }
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); }
private void Awake() { unit = GetComponent <Unit>(); worldGrid = GameObject.FindGameObjectWithTag("Scripts").GetComponent <WorldGridManager>(); }
private void Start() { worldGrid = GetComponent <WorldGridManager>(); }