public BoardTile(BoardMaker.BoardArea aType, float rot) { areaType = aType; rotation = rot; }
public static BoardTile[,] MakeBoard(Vector2Int size) { Vector2 dimensionVec = size; if (dimensionVec == Vector2.zero) { dimensionVec = Vector2.one * 4; } float boardXSize = dimensionVec.x; float boardYSize = dimensionVec.y; BoardTile[,] board = new BoardTile[(int)boardXSize, (int)boardYSize]; BoardMaker.BoardArea currentArea = BoardMaker.BoardArea.Middle; //this is used to make checking much easier float rotation = 0; //Tell cam Where middle is //load up a basic board size x board size chess board for (int x = 0; x < boardXSize; x++) { for (int y = 0; y < boardYSize; y++) { currentArea = BoardMaker.BoardArea.Middle; rotation = 0f; ///////Edge checks //check if Left edge if (x == 0 && y != 0 && y != boardYSize - 1) { //0 currentArea = BoardMaker.BoardArea.Edge; rotation = 0; } //check if right edge if (x == boardXSize - 1 && y != 0 && y != boardYSize - 1) { //180 currentArea = BoardMaker.BoardArea.Edge; rotation = 180f; } //check if Top edge if (y == 0 && x != 0 && x != boardXSize - 1) { //-90 currentArea = BoardMaker.BoardArea.Edge; rotation = 90f; } //check if bottom edge if (y == boardYSize - 1 && x != 0 && x != boardXSize - 1) { //90 currentArea = BoardMaker.BoardArea.Edge; rotation = -90f; } //Corners //bottom left if (x == 0 && y == 0) { //0 currentArea = BoardMaker.BoardArea.Corner; rotation = 90f; } //Bottom right if (x == boardXSize - 1 && y == 0) { //90 currentArea = BoardMaker.BoardArea.Corner; rotation = 180f; } //Top right if (x == boardXSize - 1 && y == boardYSize - 1) { //180 currentArea = BoardMaker.BoardArea.Corner; rotation = 270f; } //Top left if (x == 0 && y == boardYSize - 1) { //270 currentArea = BoardMaker.BoardArea.Corner; rotation = 0f; } board[x, y] = new BoardTile(currentArea, rotation); } } return(board); }
public static BoardTile[,] MakeBoard(Vector2Int size, float donutHoleSize) { Vector2 dimensionVec = size; if (dimensionVec == Vector2.zero) { dimensionVec = Vector2.one * 4; } float boardXSize = dimensionVec.x; float boardYSize = dimensionVec.y; BoardTile[,] board = new BoardTile[(int)boardXSize, (int)boardYSize]; BoardMaker.BoardArea currentArea = BoardMaker.BoardArea.Middle; //this is used to make checking much easier float rotation = 0; int[,] circleArray = DrawShape(dimensionVec, donutHoleSize); //Tell cam Where middle is //load up a basic board size x board size chess board for (int x = 0; x < boardXSize; x++) { for (int y = 0; y < boardYSize; y++) { if (circleArray[x, y] == 1) { bool study = false; //if (x == 1 && y == 2) { print("Case study!"); study = true; } //Get type int tileValue = 0; if (y + 1 < dimensionVec.y) { tileValue += circleArray[x, y + 1]; } //if (study) print("y + 1 = " + tileValue); if (y - 1 >= 0) { tileValue += circleArray[x, y - 1]; } // if (study) print("y - 1 = " + tileValue); if (x + 1 < dimensionVec.x) { tileValue += circleArray[x + 1, y]; } //if (study) print("x + 1 = " + tileValue); if (x - 1 >= 0) { tileValue += circleArray[x - 1, y]; } //if (study) print("x - 1 = " + tileValue); //if (study)print("Study results = " + tileValue); switch (tileValue) { case 2: currentArea = BoardMaker.BoardArea.Corner; break; case 3: currentArea = BoardMaker.BoardArea.Edge; break; default: currentArea = BoardMaker.BoardArea.Middle; break; } // get rotation rotation = CalcRotation(circleArray, new Vector2Int(x, y), currentArea); //CalcRotation(new Vector2Int(x, y), dimensionVec, currentArea); board[x, y] = new BoardTile(currentArea, rotation); } else { board[x, y] = new BoardTile(BoardMaker.BoardArea.Empty, 0); } } } return(board); }
static float CalcRotation(int[,] array, Vector2Int gridIndex, BoardMaker.BoardArea type) { //middle if (type == BoardMaker.BoardArea.Middle) { return(0); } int north, south, east, west; north = south = west = east = 0; if (gridIndex.y + 1 < array.GetLength(1)) { north = array[gridIndex.x, gridIndex.y + 1]; } if (gridIndex.y - 1 >= 0) { south = array[gridIndex.x, gridIndex.y - 1]; } if (gridIndex.x + 1 < array.GetLength(0)) { east = array[gridIndex.x + 1, gridIndex.y]; } if (gridIndex.x - 1 >= 0) { west = array[gridIndex.x - 1, gridIndex.y]; } if (type == BoardMaker.BoardArea.Corner) { if (north + west == 0) { return(0); } if (south + west == 0) { return(90); } if (north + east == 0) { return(270); } if (south + east == 0) { return(180); } } else { if (north == 0) { return(270); } if (east == 0) { return(180); } if (west == 0) { return(0); } if (south == 0) { return(90); } } //shouldn't reach here return(0); }
//Calculates the rotation of Edge and Corner pieces static float CalcRotation(Vector2Int gridIndex, Vector2 gridMax, BoardMaker.BoardArea type) { if (type.Equals(BoardMaker.BoardArea.Middle)) { return(0); } if (type.Equals(BoardMaker.BoardArea.Corner)) { //Corner if (gridIndex.y < gridMax.y / 2 - 1 && gridIndex.x > gridMax.x / 2 - 1) { //bottom right quadrant return(180);//0; } else if (gridIndex.y > gridMax.y / 2 - 1 && gridIndex.x > gridMax.x / 2 - 1) { //bottom left quadrant return(270f); } else if (gridIndex.y > gridMax.y / 2 - 1 && gridIndex.x < gridMax.x / 2 - 1) { //top left quadrant return(0);// 180f; } else { //top right quadrant return(90f); } } else { //Edge //North int northDist = (int)gridMax.x - gridIndex.x; //East int eastDist = gridIndex.y; //South int southDist = gridIndex.x; //West int westDist = (int)gridMax.y - gridIndex.y; //Smallest <Couldnt figure out a sexier way to do this, im a lil tired tho so i dont feel too bad> int smallDist = Mathf.Min(new int[] { northDist, eastDist, southDist, westDist }); if (smallDist == northDist) { return(180); } if (smallDist == eastDist) { return(90f); } if (smallDist == southDist) { return(0f); } if (smallDist == westDist) { return(270f); } //Shouldnt reach here... return(0); } }