public bool moveUnit(int _row, int _col) { if (isInWalkingRange(_row, _col)) { transform.position = new Vector3(walkGraph.getNode(_row, _col).x, walkGraph.getNode(_row, _col).y, transform.position.z); setActionRangeGrid(minRng, maxRng, _row, _col, 5); return(true); } return(false); }
public void setWalkRangeGrid() { walkGraph = new LocGraph(mvt, row, column); walkGraph.setDrawX(transform.position.x); walkGraph.setDrawY(transform.position.y); Queue <LocNode> queue = new Queue <LocNode>(); walkGraph.addNode(row, column, column, (GameMapping.map.unitMap.GetLength(0) - 1) - row, 0); queue.Enqueue(walkGraph.getNode(row, column)); int count = queue.Count; int idx = 0; while (idx < mvt) { while (count > 0) { LocNode node = queue.Dequeue(); count--; if (node.row - 1 >= 0 && !GameMapping.map.occupied[node.row - 1, node.column] && !walkGraph.nodeExists(node.row - 1, node.column)) { walkGraph.addNode(node.row - 1, node.column, node.x, node.y + 1, idx); queue.Enqueue(walkGraph.getNode(node.row - 1, node.column)); } if (node.column + 1 < GameMapping.map.occupied.GetLength(1) && !GameMapping.map.occupied[node.row, node.column + 1] && !walkGraph.nodeExists(node.row, node.column + 1)) { walkGraph.addNode(node.row, node.column + 1, node.x + 1, node.y, idx); queue.Enqueue(walkGraph.getNode(node.row, node.column + 1)); } if (node.row + 1 < GameMapping.map.occupied.GetLength(0) && !GameMapping.map.occupied[node.row + 1, node.column] && !walkGraph.nodeExists(node.row + 1, node.column)) { walkGraph.addNode(node.row + 1, node.column, node.x, node.y - 1, idx); queue.Enqueue(walkGraph.getNode(node.row + 1, node.column)); } if (node.column - 1 >= 0 && !GameMapping.map.occupied[node.row, node.column - 1] && !walkGraph.nodeExists(node.row, node.column - 1)) { walkGraph.addNode(node.row, node.column - 1, node.x - 1, node.y, idx); queue.Enqueue(walkGraph.getNode(node.row, node.column - 1)); } } count = queue.Count; idx++; } }