本文整理汇总了C++中Rectangle::CollidesWith方法的典型用法代码示例。如果您正苦于以下问题:C++ Rectangle::CollidesWith方法的具体用法?C++ Rectangle::CollidesWith怎么用?C++ Rectangle::CollidesWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rectangle
的用法示例。
在下文中一共展示了Rectangle::CollidesWith方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
void Game::Update()
{
Rectangle* frogRect = new Rectangle(frog->GetX() ,frog->GetY() , 21, 15);
// Check if frog collides with cars
for (int i = 0; i < cars.size(); i++)
{
Rectangle* carRect = new Rectangle(cars[i]->GetX(), cars[i]->GetY(), 21, 15);
if (frogRect->CollidesWith(carRect))
{
// Respawn frog to start position and lose 1 life
frog->Die();
}
}
// Check if frog collides with logs
for (int i = 0; i < logs.size(); i++)
{
Rectangle* logRect = new Rectangle(logs[i]->GetX(), logs[i]->GetY(), 96, 17);
if (frogRect->CollidesWith(logRect))
{
frog->MatchSpeed(logs[i]->GetSpeed());
// Make frog stay on the log while moving
//frog->SetPosition(logs[i]->GetX(), logs[i]->GetY());
}
}
// Check if frog collides with turtles
for (int i = 0; i < turtles.size(); i++)
{
Rectangle* turtleRect = new Rectangle(turtles[i]->GetX(), turtles[i]->GetY(), 21, 15);
if (frogRect->CollidesWith(turtleRect))
{
// Make frog stay on turtles while moving
frog->SetPosition(turtles[i]->GetX(), turtles[i]->GetY());
}
}
// Prevent the player to get out of bounds
if (frog->GetX() <= 0 || frog->GetX() >= 516 || frog->GetY() <= 0 || frog->GetY() >= 560)
{
frog->Die();
}
}