//0 up , 1 right , 2 down , 3 left public bool CheckIfRoomAvailable(int direction, out Vector2 position, bool targetIsPlayer = false) { Coordinate aux; bool enoughRoom = true; Vector2 auxPos; switch (direction) { case 0: for (int i = 0; i < count; i++) { aux = currentBlockGroup[i]; if (roomGrid.CheckAvailableSpace(aux.x, aux.y - 1, type, gameObject.GetInstanceID(), targetIsPlayer) == false) { enoughRoom = false; break; } } break; case 1: for (int i = 0; i < count; i++) { aux = currentBlockGroup[i]; if (roomGrid.CheckAvailableSpace(aux.x + 1, aux.y, type, gameObject.GetInstanceID(), targetIsPlayer) == false) { enoughRoom = false; break; } } break; case 2: for (int i = 0; i < count; i++) { aux = currentBlockGroup[i]; if (roomGrid.CheckAvailableSpace(aux.x, aux.y + 1, type, gameObject.GetInstanceID(), targetIsPlayer) == false) { enoughRoom = false; break; } } break; case 3: for (int i = 0; i < count; i++) { aux = currentBlockGroup[i]; if (roomGrid.CheckAvailableSpace(aux.x - 1, aux.y, type, gameObject.GetInstanceID(), targetIsPlayer) == false) { enoughRoom = false; break; } } break; case 4: for (int i = 0; i < count; i++) { aux = currentBlockGroup[i]; if ((roomGrid.CheckAvailableSpace(aux.x + 1, aux.y, type, gameObject.GetInstanceID(), targetIsPlayer) == false) || (roomGrid.CheckAvailableSpace(aux.x + 1, aux.y - 1, type, gameObject.GetInstanceID(), targetIsPlayer) == false) || (roomGrid.CheckAvailableSpace(aux.x, aux.y - 1, type, gameObject.GetInstanceID(), targetIsPlayer) == false)) { enoughRoom = false; break; } } break; case 5: for (int i = 0; i < count; i++) { aux = currentBlockGroup[i]; if ((roomGrid.CheckAvailableSpace(aux.x + 1, aux.y, type, gameObject.GetInstanceID(), targetIsPlayer) == false) || (roomGrid.CheckAvailableSpace(aux.x + 1, aux.y + 1, type, gameObject.GetInstanceID(), targetIsPlayer) == false) || (roomGrid.CheckAvailableSpace(aux.x, aux.y + 1, type, gameObject.GetInstanceID(), targetIsPlayer) == false)) { enoughRoom = false; break; } } break; case 6: for (int i = 0; i < count; i++) { aux = currentBlockGroup[i]; if ((roomGrid.CheckAvailableSpace(aux.x - 1, aux.y, type, gameObject.GetInstanceID(), targetIsPlayer) == false) || (roomGrid.CheckAvailableSpace(aux.x - 1, aux.y + 1, type, gameObject.GetInstanceID(), targetIsPlayer) == false) || (roomGrid.CheckAvailableSpace(aux.x, aux.y + 1, type, gameObject.GetInstanceID(), targetIsPlayer) == false)) { enoughRoom = false; break; } } break; case 7: for (int i = 0; i < count; i++) { aux = currentBlockGroup[i]; if ((roomGrid.CheckAvailableSpace(aux.x - 1, aux.y, type, gameObject.GetInstanceID(), targetIsPlayer) == false) || (roomGrid.CheckAvailableSpace(aux.x - 1, aux.y - 1, type, gameObject.GetInstanceID(), targetIsPlayer) == false) || (roomGrid.CheckAvailableSpace(aux.x, aux.y - 1, type, gameObject.GetInstanceID(), targetIsPlayer) == false)) { enoughRoom = false; break; } } break; } if (enoughRoom) { auxPos = CalculateCenterOfCoordinates(direction); } else { auxPos = new Vector2(-1, -1); } position = auxPos; return(enoughRoom); }