本文整理汇总了C++中Level::GetTile方法的典型用法代码示例。如果您正苦于以下问题:C++ Level::GetTile方法的具体用法?C++ Level::GetTile怎么用?C++ Level::GetTile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Level
的用法示例。
在下文中一共展示了Level::GetTile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CausesCollision
// Checks is the given movement will result in a collision.
bool Player::CausesCollision(sf::Vector2f movement, Level& level)
{
// Get the tiles that the four corners other player are overlapping with.
Tile* overlappingTiles[4];
sf::Vector2f newPosition = m_position + movement;
// Top left.
overlappingTiles[0] = level.GetTile(sf::Vector2f(newPosition.x - 14.f, newPosition.y - 14.f));
// Top right.
overlappingTiles[1] = level.GetTile(sf::Vector2f(newPosition.x + 14.f, newPosition.y - 14.f));
// Bottom left.
overlappingTiles[2] = level.GetTile(sf::Vector2f(newPosition.x - 14.f, newPosition.y + 14.f));
// Bottom right.
overlappingTiles[3] = level.GetTile(sf::Vector2f(newPosition.x + 14.f, newPosition.y + 14.f));
// If any of the overlapping tiles are solid there was a collision.
for (int i = 0; i < 4; i++)
{
if (level.IsSolid(overlappingTiles[i]->columnIndex, overlappingTiles[i]->rowIndex))
return true;
}
// If we've not returned yet no collisions were found.
return false;
}
示例2: Perform
bool MovementAction::Perform() {
Level *level = unit->GetCurrentLevel();
const Tile& t = level->GetTile(unit->GetPosition() + vector);
if ( t.SatisfyAll( unit->type->travel_conditions ) ) {
unit->Move(vector);
}
return true;
}
示例3: PreCondition
bool MovementAction::PreCondition() {
Level *level = unit->GetCurrentLevel();
const Tile& t = level->GetTile(unit->GetPosition() + vector);
//TODO: Also check if any potential unit would agree to a swap
if ( t.SatisfyAll( unit->type->travel_conditions )) {
return false;
}
return true;
}
示例4: 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.
//.........这里部分代码省略.........