本文整理汇总了C++中Level::GetSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Level::GetSize方法的具体用法?C++ Level::GetSize怎么用?C++ Level::GetSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Level
的用法示例。
在下文中一共展示了Level::GetSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GenerateLevel
void SimpleDungeonGenerator::GenerateLevel(Level& level) {
const sf::Vector2u& size = level.GetSize();
const Tile& void_tile = const_access(level.GetMapType()->generator_tiles, "void");
int rooms = rand() % (room_count_max - room_count_min) + room_count_min;
for(int i = 0; i < rooms; i++) {
int size_x = rand() % (room_size_max.x - room_size_min.x) + room_size_min.x;
int size_y = rand() % (room_size_max.y - room_size_min.y) + room_size_min.y;
}
}
示例2: UpdatePathfinding
// Recalculates the enemies path finding.
void Enemy::UpdatePathfinding(Level& level, sf::Vector2f playerPosition)
{
// Create all variables.
std::vector<Tile*> openList;
std::vector<Tile*> closedList;
std::vector<Tile*> pathList;
std::vector<Tile*>::iterator position;
Tile* currentNode;
// Reset all nodes.
level.ResetNodes();
// Store the start and goal nodes.
Tile* startNode = level.GetTile(m_position);
Tile* goalNode = level.GetTile(playerPosition);
// Check we have a valid path to find. If not we can just end the function as there's no path to find.
if (startNode == goalNode)
{
// Clear the vector of target positions.
m_targetPositions.clear();
// Exit the function.
return;
}
// Pre-compute our H cost (estimated cost to goal) for each node.
for (int i = 0; i < level.GetSize().x; i++)
{
for (int j = 0; j < level.GetSize().y; j++)
{
int rowOffset, heightOffset;
Tile* node = level.GetTile(i, j);
heightOffset = abs(node->rowIndex - goalNode->rowIndex);
rowOffset = abs(node->columnIndex - goalNode->columnIndex);
node->H = heightOffset + rowOffset;
}
}
// Add the start node to the open list.
openList.push_back(startNode);
// While we have values to check in the open list.
while (!openList.empty())
{
// Find the node in the open list with the lowest F value and mark it as current.
int lowestF = INT_MAX;
for (Tile* tile : openList)
{
if (tile->F < lowestF)
{
lowestF = tile->F;
currentNode = tile;
}
}
// Remove the current node from the open list and add it to the closed list.
position = std::find(openList.begin(), openList.end(), currentNode);
if (position != openList.end())
openList.erase(position);
closedList.push_back(currentNode);
// Find all valid adjacent nodes.
std::vector<Tile*> adjacentTiles;
Tile* node;
// Top.
node = level.GetTile(currentNode->columnIndex, currentNode->rowIndex - 1);
if ((node != nullptr) && (level.IsFloor(*node)))
{
adjacentTiles.push_back(level.GetTile(currentNode->columnIndex, currentNode->rowIndex - 1));
}
// Right.
node = level.GetTile(currentNode->columnIndex + 1, currentNode->rowIndex);
if ((node != nullptr) && (level.IsFloor(*node)))
{
adjacentTiles.push_back(level.GetTile(currentNode->columnIndex + 1, currentNode->rowIndex));
}
// Bottom.
node = level.GetTile(currentNode->columnIndex, currentNode->rowIndex + 1);
if ((node != nullptr) && (level.IsFloor(*node)))
{
adjacentTiles.push_back(level.GetTile(currentNode->columnIndex, currentNode->rowIndex + 1));
}
// Left.
node = level.GetTile(currentNode->columnIndex - 1, currentNode->rowIndex);
if ((node != nullptr) && (level.IsFloor(*node)))
{
adjacentTiles.push_back(level.GetTile(currentNode->columnIndex - 1, currentNode->rowIndex));
}
// For all adjacent nodes.
//.........这里部分代码省略.........