public bool CheckCollisionWithBotWall(Shape shape, UnityEngine.Vector3 movementVector) { List<Coordinate> filledGridPositions = shape.GetCurrentGridPosition (); foreach (Coordinate pos in filledGridPositions) { if (Math.Abs (pos.row + movementVector.y) >= mRowCount) return true; } return false; }
public bool CheckCollisionWithRightWall(Shape shape, UnityEngine.Vector3 movementVector) { List<Coordinate> filledGridPositions = shape.GetCurrentGridPosition (); foreach (Coordinate pos in filledGridPositions) { if (pos.column + movementVector.x >= mColumnCount) { return true; } } return false; }
public bool CheckCollisionWithTopWall(Shape shape, UnityEngine.Vector3 movementVector) { List<Coordinate> filledGridPositions = shape.GetCurrentGridPosition (); foreach (Coordinate pos in filledGridPositions) { if (pos.row + movementVector.y > 0) { return true; } } return false; }
private void AddCurrentShapeToSceneBitGrid(Shape shape, bool val) { List<Coordinate> filledGridPositions = shape.GetCurrentGridPosition (); foreach (Coordinate pos in filledGridPositions) { mSceneGrid [pos.row, pos.column] = val; } mSceneGrid.UpdateRowBytes (); }
//Returns information on each sub-block of the passed in Shape public List<CellInformation> GetCellInformation(Shape s, UnityEngine.Vector3 movementVector) { List<CellInformation> neighbors = new List<CellInformation> (); List<Coordinate> filledGridPositions = s.GetCurrentGridPosition (); foreach (AssemblyCSharp.Coordinate rowCol in filledGridPositions) { CellInformation info = new CellInformation (); info.coordinate.row = rowCol.row + (int)movementVector.y; info.coordinate.column = rowCol.column + (int)movementVector.x; int rowCount = mRowCount * -1; if (info.coordinate.row > 0 || info.coordinate.row <= rowCount || info.coordinate.column < 0 || info.coordinate.column >= mColumnCount) return null; int right = info.coordinate.column + 1; int left = info.coordinate.column - 1; int up = info.coordinate.row + 1; int down = info.coordinate.row - 1; if (up <= 0 && mSceneGrid [up, info.coordinate.column] == true) { info.TopNeighborStatus = TetrisGridCellStatus.Filled; } if (right < mColumnCount && mSceneGrid [info.coordinate.row, right] == true) { info.RightNeighborStatus = TetrisGridCellStatus.Filled; } if (right == mColumnCount) //boost a little bit on the sides of scores don't clump in the middle info.RightNeighborStatus = TetrisGridCellStatus.Wall; if (left >= 0 && mSceneGrid [info.coordinate.row, left] == true) { info.LeftNeighborStatus = TetrisGridCellStatus.Filled; } if (left == -1) info.LeftNeighborStatus = TetrisGridCellStatus.Wall; if (down > rowCount && mSceneGrid [down, info.coordinate.column] == true) { info.BotNeighborStatus = TetrisGridCellStatus.Filled; } if (down > rowCount && mSceneGrid [down, info.coordinate.column] == false && filledGridPositions.Count (x => x.row == (rowCol.row - 1) && x.column == rowCol.column) == 0) { info.BotNeighborStatus = TetrisGridCellStatus.Open; } if (down == rowCount) { info.BotNeighborStatus = TetrisGridCellStatus.Wall; } neighbors.Add (info); } return neighbors; }
//These collision detection functions are made public so they can be accessed by the AI public bool DoAnyShapesCollideInScene(Shape shape, UnityEngine.Vector3 movementVector) { List<Coordinate> filledGridPositions = shape.GetCurrentGridPosition (); foreach (Coordinate pos in filledGridPositions) { if (mSceneGrid [pos.row + (int)movementVector.y, pos.column + (int)movementVector.x] == true) return true; } return false; }