//设置怪物的路线 /* 将拐点添加到容器中 */ private static void SetMonsterRoute() { byte currentDirection = GetNextGridDirection(StartGrid, MoveRoute.NONE), lastDirection = MoveRoute.NONE; GPosition currentPosition = new GPosition(), lastPosition = new GPosition(); uint i = 0, max = (uint)(Map.Length * Map[0].Length); uint index = 0; for (currentPosition.CopyFrom(StartGrid), lastPosition.CopyFrom(StartGrid); i < max; i++) { //遇到拐点,则保存到容器中 if (currentDirection != lastDirection) { lastDirection = currentDirection; MonsterRoute.Add(index++, new Position(lastPosition, UIFunction.GetPixelPosition(lastPosition), currentDirection)); } //如果达到终点,则结束 if (currentPosition.Equals(EndGrid)) { MonsterRoute.Add(index++, new Position(currentPosition, UIFunction.GetPixelPosition(currentPosition), currentDirection)); break; } lastPosition.CopyFrom(currentPosition); //将当前位置保存到上一个位置 //获取下一个位置的方向,并避免180度回头的情况 currentDirection = GetNextGridDirection(currentPosition, currentDirection); switch (currentDirection) { case MoveRoute.UP: currentPosition.line -= 1; break; case MoveRoute.DOWN: currentPosition.line += 1; break; case MoveRoute.LEFT: currentPosition.column -= 1; break; case MoveRoute.RIGHT: currentPosition.column += 1; break; } } }
public void SetGridPosition(GPosition arg) { grid_pos.CopyFrom(arg); }