/// <summary> /// ルートを変更して移動する関数 /// </summary> void rootChangeMove() { if (state != State.ROOT_CHANGE) { return; } int x = (int)retCell().x; int y = (int)retCell().y; if (astarstate == AstarState.SEARCH) { while (astar_trycount < 5000) { nodemanager.removeOpenNode(node); nodemanager.openAround(node); node = nodemanager.searchMinScoreNodeFromOpenNodeList(); if (node == null) { break; } if (node.x == goalpos.x && node.y == goalpos.y) { nodemanager.removeOpenNode(node); node.getRootList(rootlist); rootlist.Reverse(); astarstate = AstarState.WORK_START; astar_trycount = 0; break; } astar_trycount++; } } else if (astarstate == AstarState.WORK_START) { if (astarmovecount >= rootlist.Count - 1) { astarmovecount = 0; state = State.ROOT_NORMALMOVE; return; } astarmovecount++; nextmovecell = new Vector2(rootlist[astarmovecount].x, rootlist[astarmovecount].y); directionChange(x, y, (int)nextmovecell.x, (int)nextmovecell.y); astarstate = AstarState.WORK; } else if (astarstate == AstarState.WORK) { float s = up_speed; directionMove(s); move_value += s; if (move_value >= mapchip.chip_size) { adjustPosition(x, y); astarstate = AstarState.WORK_START; move_value = 0; } } }
/// <summary> /// A*準備 /// </summary> void astarSetup() { rootRandomDecide(); astarstate = AstarState.SEARCH; int x = (int)retCell().x; int y = (int)retCell().y; var startpos = new AStar.RootPosition(x, y); Vector2 tempgoalpos; tempgoalpos = getGoalCell(); goalpos = new AStar.RootPosition((int)tempgoalpos.x, (int)tempgoalpos.y); nodemanager = new AStar.NodeManager(goalpos.x, goalpos.y, mapchip); node = nodemanager.openNode(startpos.x, startpos.y, 0, null); nodemanager.addOpenNode(node); rootlist = new List <AStar.RootPosition>(); astar_trycount = 0; astarmovecount = 0; }