// Use this for initialization void Start() { //ends = 2; //rotations = 0; pieceName = "Two Door Hallway"; //Set endsUsed relative to what ends are being used //NOTE- Exact values are not being used because sometimes they do not register exact values (DONT KNOW WHY-TRIED TO FIX FOR HOURS) endsUsed = new bool[4]; if (this.gameObject.transform.eulerAngles.y >= 85 && this.gameObject.transform.eulerAngles.y <= 95) { endsUsed [0] = true; endsUsed [1] = false; endsUsed [2] = true; endsUsed [3] = false; } else { endsUsed [0] = false; endsUsed [1] = true; endsUsed [2] = false; endsUsed [3] = true; } int curRow, curColumn; curRow = InstantiateBlocks.getCurRow(this.gameObject.transform.position); curColumn = InstantiateBlocks.getCurColumn(this.gameObject.transform.position); if (curRow != -1 && curRow != InstantiateBlocks.getRows() && curColumn != -1 && curColumn != InstantiateBlocks.getColumns()) { InstantiateBlocks.getAllBlocks() [curRow, curColumn].GetComponent <Block> ().setEnds(endsUsed [0], endsUsed [1], endsUsed [2], endsUsed [3]); InstantiateBlocks.getAllBlocks() [curRow, curColumn].GetComponent <Block> ().setUsed(true); } }
// Use this for initialization void Start() { blocks = InstantiateBlocks.getAllBlocks(); rows = InstantiateBlocks.getRows(); columns = InstantiateBlocks.getColumns(); curRow = InstantiateBlocks.getCurRow(GetComponentInParent <Block> ().gameObject.transform.position); curColumn = InstantiateBlocks.getCurColumn(GetComponentInParent <Block> ().gameObject.transform.position); }
void Update() { //If the raycast finds an endpiece and the player is close and presses E, set isPlacingPiece to true and begin placing piece if (selectedTarget.tag == "EndPiece" && Vector3.Distance(selectedTarget.transform.position, player.transform.position) < 25) { if (Input.GetKeyDown(KeyCode.E)) { isPlacingPiece = true; checkAvailability(); Debug.Log(selectedTarget.name); selectedTargetName = selectedTarget.name; } } //Raycast in front of player and store object that is hit RaycastHit hit; Ray ray = this.gameObject.GetComponentInChildren <Camera> ().ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 25)) { selectedTarget = hit.transform.gameObject; } if (isPlacingPiece) { //STOP Player movement and display mouse FPC.enabled = false; Cursor.visible = true; Cursor.lockState = CursorLockMode.None; Time.timeScale = 0; } else { FPC.enabled = true; Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; Time.timeScale = 1; } //DEBUG PURPOSES-WILL ERROR-C WILL CLEAR MAP SO THAT IT IS NO LONGER SAVED if (Input.GetKeyDown(KeyCode.C)) { for (int x = 0; x < InstantiateBlocks.getRows(); x++) { for (int z = 0; z < InstantiateBlocks.getColumns(); z++) { PlayerPrefs.SetInt(x.ToString() + z.ToString() + "isUsed", 0); PlayerPrefs.SetInt(x.ToString() + z.ToString() + "pieceType", 0); } } } }
//To be added to when more blocks are available public static bool[] checkAvailability(int refRow, int refColumn) { bool[] possibilities = new bool[11]; //1 - two door room - 0 degrees //East - West //2 - two door room - 90 degrees //North - South //3 - corner room - 0 degrees //North - East //4 - corner room - 90 degrees //East - South //5 - corner room - 180 degrees //South - West //6 - corner room - 270 degrees //North - West //7 - three door room - 0 degrees //East - South - West //8 - three door room - 90 degrees //North - South - West //9 - three door room - 180 degrees //North - East - West //10 - three door room - 270 degrees //North - East - South //11 - four door room //All Directions //Calculate if able to place a certain block heres #region TwoDoorHallway EastWest if (refColumn != InstantiateBlocks.getColumns() - 1 && refColumn != 0) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3] && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { if (refRow != InstantiateBlocks.getRows() - 1 && refRow != 0) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed() || getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed() && getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if ((!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && !getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2])) { possibilities [0] = true; } } else if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed()) { if ((!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0])) { possibilities [0] = true; } } else if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if ((!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2])) { possibilities [0] = true; } } } else { possibilities [0] = true; } } else if (refRow == InstantiateBlocks.getRows() - 1) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { possibilities [0] = true; } } else { possibilities [0] = true; } } else if (refRow == 0) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0]) { possibilities [0] = true; } } else { possibilities [0] = true; } } } } #endregion #region TwoDoorHallway NorthSouth if (refRow != InstantiateBlocks.getRows() - 1 && refRow != 0) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { if (refColumn != InstantiateBlocks.getColumns() - 1 && refColumn != 0) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed() || getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed() && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if ((!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3] && !getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1])) { possibilities [1] = true; } } else if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if ((!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3])) { possibilities [1] = true; } } else if (getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if ((!getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1])) { possibilities [1] = true; } } } else { possibilities [1] = true; } } else if (refColumn == InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [1] = true; } } else { possibilities [1] = true; } } else if (refColumn == 0) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [1] = true; } } else { possibilities [1] = true; } } } } #endregion #region CornerRoom NorthEast if (refRow != 0 && refColumn != InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2] && getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { if (refRow != InstantiateBlocks.getRows() - 1 && refColumn != 0) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed() || getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed() && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && !getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [2] = true; } } else if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0]) { possibilities [2] = true; } } else if (getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [2] = true; } } } else { possibilities [2] = true; } } else if (refRow == InstantiateBlocks.getRows() - 1 && refColumn != 0) { if (getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [2] = true; } } else { possibilities [2] = true; } } else if (refRow != InstantiateBlocks.getRows() - 1 && refColumn == 0) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0]) { possibilities [2] = true; } } else { possibilities [2] = true; } } else { possibilities [2] = true; } } } #endregion #region CornerRoom SouthEast if (refColumn != InstantiateBlocks.getColumns() - 1 && refRow != InstantiateBlocks.getRows() - 1) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { if (refColumn != 0 && refRow != 0) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed() || getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed() && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2] && !getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [3] = true; } } else if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { possibilities [3] = true; } } else if (getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [3] = true; } } } else { possibilities [3] = true; } } else if (refColumn == 0 && refRow != 0) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { possibilities [3] = true; } } else { possibilities [3] = true; } } else if (refRow == 0 && refColumn != 0) { if (getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [3] = true; } } else { possibilities [3] = true; } } else { possibilities [3] = true; } } } #endregion #region CornerRoom SouthWest if (refRow != InstantiateBlocks.getRows() - 1 && refColumn != 0) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { if (refRow != 0 && refColumn != InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed() || getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed() && getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2] && !getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [4] = true; } } else if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { possibilities [4] = true; } } else if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [4] = true; } } } else { possibilities [4] = true; } } else if (refRow == 0 && refColumn != InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [4] = true; } } else { possibilities [4] = true; } } else if (refRow != 0 && refColumn == InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { possibilities [4] = true; } } else { possibilities [4] = true; } } else { possibilities [4] = true; } } } #endregion #region CornerRoom NorthWest if (refColumn != 0 && refRow != 0) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2] && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { if (refColumn != InstantiateBlocks.getColumns() - 1 && refRow != InstantiateBlocks.getRows() - 1) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed() || getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed() && getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && !getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [5] = true; } } else if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0]) { possibilities [5] = true; } } else if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [5] = true; } } } else { possibilities [5] = true; } } else if (refColumn == InstantiateBlocks.getColumns() - 1 && refRow != InstantiateBlocks.getRows() - 1) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0]) { possibilities [5] = true; } } else { possibilities [5] = true; } } else if (refColumn != InstantiateBlocks.getColumns() - 1 && refRow == InstantiateBlocks.getRows() - 1) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { if (!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [5] = true; } } else { possibilities [5] = true; } } else { possibilities [5] = true; } } } #endregion #region ThreeDoorHallway EastSouthWest if (refColumn != 0 && refColumn != InstantiateBlocks.getColumns() - 1 && refRow != InstantiateBlocks.getRows() - 1) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1] && getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { if (refRow != 0) { if (getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed() && !getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { possibilities [6] = true; } else if (!getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().getUsed()) { possibilities [6] = true; } } else { possibilities [6] = true; } } } #endregion #region ThreeDoorHallway NorthSouthWest if (refRow != 0 && refRow != InstantiateBlocks.getRows() - 1 && refColumn != 0) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1] && getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { if (refColumn != InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed() && !getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3]) { possibilities [7] = true; } else if (!getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().getUsed()) { possibilities [7] = true; } } else { possibilities [7] = true; } } } #endregion #region ThreeDoorHallway NorthEastWest if (refRow != 0 && refColumn != 0 && refColumn != InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3] && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1] && getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { if (refRow != InstantiateBlocks.getRows() - 1) { if (getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed() && !getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0]) { possibilities [8] = true; } else if (!getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().getUsed()) { possibilities [8] = true; } } else { possibilities [8] = true; } } } #endregion #region ThreeDoorHallway NorthEastSouth if (refRow != 0 && refRow != InstantiateBlocks.getRows() - 1 && refColumn != InstantiateBlocks.getColumns() - 1) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3] && getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2]) { if (refColumn != 0) { if (getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed() && !getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [9] = true; } else if (!getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().getUsed()) { possibilities [9] = true; } } else { possibilities [9] = true; } } } #endregion #region FourDoorHallway if (refRow != 0 && refColumn != InstantiateBlocks.getColumns() - 1 && refRow != InstantiateBlocks.getRows() - 1 && refColumn != 0) { if (getAllBlocks() [refRow, refColumn + 1].GetComponent <Block> ().Ends [3] && getAllBlocks() [refRow + 1, refColumn].GetComponent <Block> ().Ends [0] && getAllBlocks() [refRow - 1, refColumn].GetComponent <Block> ().Ends [2] && getAllBlocks() [refRow, refColumn - 1].GetComponent <Block> ().Ends [1]) { possibilities [10] = true; } } #endregion return(possibilities); }