本文整理汇总了C++中Direction::Opposite方法的典型用法代码示例。如果您正苦于以下问题:C++ Direction::Opposite方法的具体用法?C++ Direction::Opposite怎么用?C++ Direction::Opposite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Direction
的用法示例。
在下文中一共展示了Direction::Opposite方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
bool Styx::Update(GameTime time)
{
Playfield const &pf = *GetPlayfield();
// create set of possibile directions to move in
std::vector<Direction> choices;
for (int n = 0; n < 4; ++n)
{
Direction dir = (Direction::Type)n;
// can't reverse direction
if (dir.Opposite() == direction)
continue;
Playfield::Element element = pf.At(location + dir.GetVector());
if (element == Playfield::Line)
{
choices.push_back(Direction::Type(n));
}
}
// if we have no where to go, reverse
if (choices.empty())
{
direction = direction.Opposite();
}
else
{
// choose new random direction
SetDirection(choices[rand() % choices.size()]);
if (move_toward_player && choices.size() > 1)
{
Point pos_player = GetRoot()->GetWorld()->GetPlayer()->GetLocation();
float min_dist = 0;
bool first = true;
foreach (Direction dir, choices)
{
float dist = (location + dir.GetVector() - pos_player).Length();
if (first || dist < min_dist)
{
first = false;
min_dist = dist;
SetDirection(dir);
}
}
}