本文整理汇总了C++中Coin::SetSoundDelay方法的典型用法代码示例。如果您正苦于以下问题:C++ Coin::SetSoundDelay方法的具体用法?C++ Coin::SetSoundDelay怎么用?C++ Coin::SetSoundDelay使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Coin
的用法示例。
在下文中一共展示了Coin::SetSoundDelay方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
/*
================================================================================
Game::Update
Gets called once per frame to perform game logic.
The parameter dt is the time elapsed since last frame (in seconds).
================================================================================
*/
void Game::Update(float dt)
{
// Update the robot
if (mRobot)
{
// If the robot has reached the last scene
// disable its controls and play game over animation
if (mScene == 6 && !mRobot->GetJumping() && !mRobot->GetFalling())
{
mRobot->SetAutoPilot(true);
}
mRobot->Update(dt);
}
// Update the coins
std::list<Coin*>::iterator coinIt = mCoins.begin();
while (coinIt != mCoins.end())
{
Coin *coin = *coinIt;
// Check if the robot collides with the coin
if (mRobot->GetCollisonRect().y < coin->GetRect().y + coin->GetRect().h)
{
if ((mRobot->GetCollisonRect().x < coin->GetRect().x + coin->GetRect().w)
&& (mRobot->GetCollisonRect().x + mRobot->GetCollisonRect().w > coin->GetRect().x))
{
if ((mRobot->GetCollisonRect().y < coin->GetRect().y + coin->GetRect().h)
&& (mRobot->GetCollisonRect().y + mRobot->GetCollisonRect().h > coin->GetRect().y))
{
//I have found that the sound is delayed...So I start it a bit earlier than the actualy delete of the Coin
if (coin->GetSoundDelay() == 0)
{
// You get 5 points!
mPoints += 5;
Mix_PlayChannel(-1, mCoinSound, 0);
coin->SetSoundDelay(1);
}
//Once it has run through 4 times then it Deletes the coin
else if (coin->GetSoundDelay() == 5)
{
coinIt = mCoins.erase(coinIt); // remove the entry from the list and advance iterator
delete coin;
coin = NULL;
}
else
{
coin->SetSoundDelay(1);
}
}
else
{
coin->Update(dt);
++coinIt;
}
}
else
{
coin->Update(dt);
++coinIt;
}
}
else
{
coin->Update(dt);
++coinIt;
}
}
// update all crawlers
std::list<Crawler*>::iterator crawlerIt = mCrawlers.begin();
while (crawlerIt != mCrawlers.end())
{
Crawler *crawler = *crawlerIt;
if (crawler->GetState() == Crawler::CRAWLER_DEAD)
{
crawlerIt = mCrawlers.erase(crawlerIt); // remove the entry from the list and advance iterator
delete crawler; // delete the object
}
else
{
// If the robot is falling from a jump or just falling
if (mRobot->GetVerticalVelocity() > 0.0 && (mRobot->GetJumping() || mRobot->GetFalling()))
{
// Check if the robot has started squashing the poor crawler
if (mRobot->GetCollisonRect().x + mRobot->GetCollisonRect().w > crawler->GetCollisionRect().x &&
mRobot->GetCollisonRect().x < crawler->GetCollisionRect().x + crawler->GetCollisionRect().w)
{
if (mRobot->GetCollisonRect().y + mRobot->GetCollisonRect().h > crawler->GetCollisionRect().y &&
mRobot->GetCollisonRect().y < crawler->GetCollisionRect().y)
{
//.........这里部分代码省略.........