当前位置: 首页>>代码示例>>C++>>正文


C++ TileNode::getLocation方法代码示例

本文整理汇总了C++中TileNode::getLocation方法的典型用法代码示例。如果您正苦于以下问题:C++ TileNode::getLocation方法的具体用法?C++ TileNode::getLocation怎么用?C++ TileNode::getLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TileNode的用法示例。


在下文中一共展示了TileNode::getLocation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TileNode

std::vector<Vec2> TMXPathFinding::getPath(Vec2 startPos, Vec2 endPos, std::vector<int> walkableGIDs, std::vector<int> obstacleGIDs) {
	open.clear();
	close.clear();

	// inizialize a goal node
	goalNode = new TileNode();
	goalNode->setLocX(endPos.x);
	goalNode->setLocY(endPos.y);

	// inizialize a start node
	startNode = new TileNode();
	startNode->setLocX(startPos.x);
	startNode->setLocY(startPos.y);
	startNode->setCostFromStart(0);
	startNode->setParent(nullptr);

	int cost = getDistance(startNode, goalNode);

	startNode->setCostToGoal(cost);
	startNode->setTotalCost();

	open.emplace(startNode, startNode->getTotalCost());

	while (open.size() != 0) {
		// Fix a Cost to check the values
		min = 32767; // std::numeric_limits<int>::max()
		TileNode *minNode;

		// Find minNode from open QUEUE
		for (auto kv : open) {
			extractNode = kv.first;
			iCost = kv.second;
			if (iCost < min) {
				min = iCost;    // Change min to the New Cost got from the open QUEUE
				minNode = extractNode;
			}
		}
		extractNode = minNode;
		open.erase(minNode); // pop node from open

		// if it's a goal, we're done
		if (extractNode->getLocation() == goalNode->getLocation()) {
			// 1- retrieve all extractNode's parents
			// 2- save into Vec2 vector
			// 3- reverse Vec2 vector
			// 4- return Vec2 vector
			std::vector<Vec2> points;
			points.push_back(extractNode->getLocation());

			int size = extractNode->getCostFromStart();
			for (int i = 0; i < size; i++) {
				points.push_back(Vec2(extractNode->getParent()->getLocation().x, extractNode->getParent()->getLocation().y));
				extractNode = extractNode->getParent();
			}
			std::reverse(points.begin(), points.end());

			return points;
		}
		else {
			for (int i = 0; i < dir; i++) {
				costToOpen = 0;
				costToClose = 0;
				inOpen = false;
				inClose = false;
				newNode = new TileNode();
				newNode->setLocX(extractNode->getLocation().x);
				newNode->setLocY(extractNode->getLocation().y);

				switch (i) {
					case 0: // left
						newNode->setLocX(-1);
						newNode->setLocY(0);
						break;
					case 1: // right
						newNode->setLocX(1);
						newNode->setLocY(0);
						break;
					case 2: // up
						newNode->setLocX(0);
						newNode->setLocY(1);
						break;
					case 3: // down
						newNode->setLocX(0);
						newNode->setLocY(-1);
						break;
					case 4: // top-left
						newNode->setLocX(-1);
						newNode->setLocY(1);
						break;
					case 5: // bottom-left
						newNode->setLocX(-1);
						newNode->setLocY(-1);
						break;
					case 6: // bottom-right
						newNode->setLocX(1);
						newNode->setLocY(-1);
						break;
					case 7: // top-right
						newNode->setLocX(1);
						newNode->setLocY(1);
//.........这里部分代码省略.........
开发者ID:smitpatel88,项目名称:TMXPathFinding,代码行数:101,代码来源:TMXPathFinding.cpp


注:本文中的TileNode::getLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。