本文整理汇总了C++中TerrainTile::Cost方法的典型用法代码示例。如果您正苦于以下问题:C++ TerrainTile::Cost方法的具体用法?C++ TerrainTile::Cost怎么用?C++ TerrainTile::Cost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TerrainTile
的用法示例。
在下文中一共展示了TerrainTile::Cost方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
PLAYER_UPDATE_STATE Player::Update(float delta_, Goal* goal_, std::vector<Bullet> bullets_, std::set<TerrainTile*> monitoredTiles_)
{
playerWaitTimer += delta_;
animationTimer += delta_;
//set animation
if (animationTimer > 0.6f)
{
animationTimer = 0.0f;
animSwitch++;
if (animSwitch % 2 == 0)
{
playerTexture = textures[0];
}
else
{
playerTexture = textures[1];
}
}
if (spotted && behaviour != FLEE)
{
cout << "behaviour == FLEE" << endl;
behaviour = FLEE;
navigationList.clear();
spotted = false;
}
//update player on normal path
//while the navigationList is not empty.
if (navigationList.empty() && behaviour == SEEK)
{
// //convert click location to tile
TerrainTile* dstTile = terrain->TileAtMouseCoords(goal_->Pos());
//convert player location to tile
TerrainTile* playerTile = terrain->TileAtMouseCoords(static_cast<int>(pos.x), static_cast<int>(pos.y));
// //get the vector of tiles to nav to
navigationList = terrain->ShortestPath(playerTile, dstTile, monitoredTiles_);
}
if (navigationList.empty() && behaviour == FLEE)
{
TerrainTile* playerTile = terrain->TileAtMouseCoords(static_cast<int>(pos.x), static_cast<int>(pos.y));
//get a new path from terrain to get away from enemy
navigationList = terrain->ClosestUnmonitoredTile(playerTile, monitoredTiles_);
//is current tile monitored?
if (std::find(monitoredTiles_.begin(), monitoredTiles_.end(), playerTile) == monitoredTiles_.end())
{
behaviour = SEEK;
}
}
////wait for x seconds
//if (navigationList.empty() && behaviour == FLEE)
//{
// cout << "behaviour == WAIT" << endl;
// behaviour = WAIT;
//}
//if (behaviour == WAIT)
//{
//
// if (playerWaitTimer > 0.1f)
// {
// playerWaitTimer = 0.0f;
// cout << "behaviour == SEEK" << endl;
// behaviour = SEEK;
// }
//}
if (!navigationList.empty())
{
//if ( behaviour != WAIT )
//{
//get the next node and move towards it
TerrainTile* nextNode = navigationList[navigationList.size() - 1];
Vector2 nextNodePos = nextNode->Pos();
//if reached pop it off the top
if ((pos - nextNode->Pos()).GetMagnitude() < 1.0f)
{
pos = nextNode->Pos();
navigationList.erase(navigationList.end() - 1);
navigationList.clear();
}
else
{
int currentTerrainCost = 1;
if ((pos - nextNode->Pos()).GetMagnitude() < TILE_SIZE * 0.5f)
{
currentTerrainCost = nextNode->Cost();
}
//.........这里部分代码省略.........