public bool CanMove(int fromX, int fromY, Orientation toOrientation) { int toX = fromX; int toY = fromY; LevelHelper.GetNextCellCoords(ref toX, ref toY, toOrientation); Debug.Log("CanMove fromX=" + fromX + "/ fromY=" + fromY + " / toX=" + toX + " / toY=" + toY); Object obj = GetObjectAtPos(toX, toY); if (obj != null) { return(obj.isTraversable()); } else { // check for out of map if (toX < m_Tile.origin.x || toX >= (m_Tile.origin.x + m_Tile.size.x) || toY < m_Tile.origin.y || toY >= (m_Tile.origin.y + m_Tile.size.y)) { return(false); } // check for out of map } return(true); }
public void Move(Orientation ori) { bool canMove = m_Logic.GetLevel().CanMove(m_Position.x, m_Position.y, ori); if (canMove) { int toX = m_Position.x; int toY = m_Position.y; LevelHelper.GetNextCellCoords(ref toX, ref toY, ori); Debug.Log("move " + ori); Put(toX, toY, ori); // event } else { Debug.Log("can't move but at least rotate"); Rotate(ori); // event } }