// 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 PlayerMoved() { //flip ant's current tile HashSet <Vector2Int> indices = new HashSet <Vector2Int>(); foreach (Ant ant in m_ants) { Vector2Int index = new Vector2Int(ant.m_row, ant.m_col); if (!indices.Contains(index)) { indices.Add(index); m_map.SetTileState(ref ant.m_row, ref ant.m_col, !m_map.GetTileState(ref ant.m_row, ref ant.m_col)); } } //move ants foreach (Ant ant in m_ants) { ant.Move(m_map); //check player intersect if (ant.m_row == m_player.m_row && ant.m_col == m_player.m_col) { Debug.Log("overlap"); GameOver(false); } } //check player exit intersect int exitRow, exitCol; m_map.WorldToGrid(m_exit.transform.position, out exitRow, out exitCol); if (m_player.m_row == exitRow && m_player.m_col == exitCol) { GameOver(true); } }
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); }