// Update is called once per frame void Update() { bool playerMoved = false; if (Input.GetButtonDown("Horizontal")) { int newCol = m_col; if (Input.GetAxisRaw("Horizontal") > 0) { newCol++; } else if (Input.GetAxisRaw("Horizontal") < 0) { newCol--; } if (!m_map.GetTileState(ref m_row, ref newCol)) { m_col = newCol; transform.position = m_map.GridToWorld(m_row, m_col); playerMoved = true; } } else if (Input.GetButtonDown("Vertical")) { int newRow = m_row; if (Input.GetAxisRaw("Vertical") > 0) { newRow--; } else if (Input.GetAxisRaw("Vertical") < 0) { newRow++; } if (!m_map.GetTileState(ref newRow, ref m_col)) { m_row = newRow; transform.position = m_map.GridToWorld(m_row, m_col); playerMoved = true; } } else if (Input.GetButtonDown("Skip")) { playerMoved = true; } if (playerMoved) { GameManager.Instance.PlayerMoved(); } }
public void Move(CellularMap map) { //move forward int[] direction = Helper.DIRECTIONS[(int)m_direction]; m_row += direction[0]; m_col += direction[1]; transform.position = map.GridToWorld(m_row, m_col); //rotate int turnDirection = map.GetTileState(ref m_row, ref m_col) ? 1 : -1; m_direction = (CardinalDirections)(Helper.BetterMod((int)m_direction + turnDirection, (int)CardinalDirections.END)); transform.rotation = Quaternion.Euler(0, (int)m_direction * -90, 0); }