private bool CheckNewPostion() { bool filled = false; for (int i = 0; i < newGroup.Length; i++) { //check if it's inside border if(!playfield.InsideBorder(newGroup[i].x + newOffset.x, newGroup[i].y + newOffset.y)) { filled = true; break; } //check if new position valid if (playfield.isBlockFilled[newGroup[i].x + newOffset.x, newGroup[i].y + newOffset.y]) {//this block is already filled bool filledBySelf = false; //check if the block is filled by itself for (int j=0;j<oldGroup.Length;j++) { if(oldGroup[j] + oldOffset == newGroup[i] + newOffset) { filledBySelf = true; break; } } if(!filledBySelf)//block is filled by other block, not valid postion { filled = true; break; } } } //Debug.Log("Check" + filled); if (filled)//not valid postion, revert { oldGroup.CopyTo(newGroup, 0); newOffset = oldOffset; } return !filled; }
private int IsValidGridPos() { bool outsideBorder = false; foreach (Transform child in transform) { Vector2 v = Playfield.RoundVec2(child.position); child.position = v; // Not inside border? if (!outsideBorder) { outsideBorder = !Playfield.InsideBorder(v); } // Y is out of bounds if (v.y < 0) { return(0); } if (outsideBorder) { // If outside the left border sets the x component to the width if (v.x < 0) { v.x = Playfield.w + v.x; // putting it on the right side } else if (v.x >= Playfield.w) { v.x = v.x - Playfield.w; // putting it on the left side } } // Block in grid cell (and not part of same group)? if (Playfield.grid[(int)v.x, (int)v.y] != null && Playfield.grid[(int)v.x, (int)v.y].parent != transform) { return(0); } } if (outsideBorder) { return(2); } return(1); }
bool isValidGridPos() { foreach (Transform child in transform) { Vector2 v = Playfield.roundVec2(child.position); if (!Playfield.InsideBorder(v)) { return(false); } if (Playfield.grid[(int)v.x, (int)v.y] != null && Playfield.grid[(int)v.x, (int)v.y].parent != transform) { return(false); } } return(true); }
//See if the position is valid bool IsValidGridPos() { foreach (Transform child in transform) { Vector2 v = Playfield.RoundVec2(child.position); // Not inside Border? if (!Playfield.InsideBorder(v)) { return(false); } // Block in grid cell (and not part of same group)? if (Playfield.grid[(int)v.x, (int)v.y] != null && Playfield.grid[(int)v.x, (int)v.y].parent != transform) { return(false); } } return(true); }
public static bool IsValidGridPos(this GameObject go) { foreach (Transform child in go.transform) { var v = Playfield.RoundVec2(child.position); // Not inside Border? if (!Playfield.InsideBorder(v)) { return(false); } // Block in grid cell (and not part of same go)? if (Grid[(int)v.x, (int)v.y] != null && Grid[(int)v.x, (int)v.y].parent != go.transform) { return(false); } } return(true); }