本文整理汇总了C++中Bot::isCurrentlyCollidable方法的典型用法代码示例。如果您正苦于以下问题:C++ Bot::isCurrentlyCollidable方法的具体用法?C++ Bot::isCurrentlyCollidable怎么用?C++ Bot::isCurrentlyCollidable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bot
的用法示例。
在下文中一共展示了Bot::isCurrentlyCollidable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void Physics::update(Game *game)
{
// REMEMBER, AT THIS POINT, ALL PLAYER INPUT AND AI
// HAVE ALREADY BEEN PROCESSED AND BOT AND PLAYER
// STATES, VELOCITIES, AND ACCELERATIONS HAVE ALREADY
// BEEN UPDATED. NOW WE HAVE TO PROCESS THE PHYSICS
// OF ALL THESE OBJECTS INTERACTING WITH EACH OTHER
// AND THE STATIC GAME WORLD. THIS MEANS WE NEED TO
// DETECT AND RESOLVE COLLISIONS IN THE ORDER THAT
// THEY WILL HAPPEN, AND WITH EACH COLLISION, EXECUTE
// ANY GAMEPLAY RESPONSE CODE, UPDATE VELOCITIES, AND
// IN THE END, UPDATE POSITIONS
// FIRST, YOU SHOULD START BY ADDING ACCELERATION TO ALL
// VELOCITIES, WHICH INCLUDES GRAVITY, NOTE THE EXAMPLE
// BELOW DOES NOT DO THAT
// FOR NOW, WE'LL JUST ADD THE VELOCITIES TO THE
// POSITIONS, WHICH MEANS WE'RE NOT APPLYING GRAVITY OR
// ACCELERATION AND WE ARE NOT DOING ANY COLLISION
// DETECTION OR RESPONSE
float timer = 0;
GameStateManager *gsm = game->getGSM();
SpriteManager *sm = gsm->getSpriteManager();
World *w = gsm->getWorld();
GameRules* gR = game->getGameRules();
vector<WorldLayer*> *layers = w->getLayers();
AnimatedSprite *player;
PhysicalProperties *pp;
TiledLayer *tL;
list<Collision*> collisions;
//finding TileLayer
for(unsigned int i = 0; i < layers->size(); i++)
{
WorldLayer *currentLayer = (*layers)[i];
if(currentLayer->hasCollidableTiles() == true)
{
tL = dynamic_cast<TiledLayer*>(currentLayer);
if(tL != 0)
{
i = layers->size();
}//end if
}//end if
}
player = sm->getPlayer();
pp = player->getPhysicalProperties();
//UPDATING ALL VELOCITIES AND DOING TILE COLLISION
pp->incVelocity(this,pp->getAccelerationX(), pp->getAccelerationY() + gravity);
collideTestWithTiles(player, tL, &collisions);
list<Bot*>::iterator botIterator = sm->getBotsIterator();
while (botIterator != sm->getEndOfBotsIterator())
{
Bot *bot = (*botIterator);
pp = bot->getPhysicalProperties();
pp->incVelocity(this, pp->getAccelerationX(), pp->getAccelerationY());
if(pp->isGravAffected() == true)
pp->incVelocity(this, 0, gravity);
collideTestWithTiles(bot, tL, &collisions);
botIterator++;
}
//HERE, COLLIDE SPRITES WITH OTHER SPRITES
collideTestWithSprites(game, player, &collisions);
botIterator = sm->getBotsIterator();
while (botIterator != sm->getEndOfBotsIterator())
{
Bot *bot = (*botIterator);
if(bot->isCurrentlyCollidable() == true);
collideTestWithSprites(game, bot, &collisions);
botIterator++;
}
//SORT COLLISIONS
collisions.sort(compare_collisionTime);
//RESOLVING ALL THE COLLISIONS
while(collisions.empty() == false)
{
Collision* currentCollision = collisions.front();
collisions.pop_front();
float colTime = currentCollision->getTOC();
CollidableObject* co1 = currentCollision->getCO1();
CollidableObject* co2 = currentCollision->getCO2();
if(colTime >= 0 && colTime <= 1)
{
pp = co1->getPhysicalProperties();
//pp->setVelocity(pp->getVelocityX()*9.99f,pp->getVelocityY()*9.99f);
pp = co2->getPhysicalProperties();
//pp->setVelocity(pp->getVelocityX()*9.99f,pp->getVelocityY()*9.99f);
//.........这里部分代码省略.........
示例2: collideTestWithSprites
//FOR NOW, TESTS SPRITES AGAINST ALL OTHER SPRITES. IF I HAVE TIME, I WILL IMPLEMENT SWEEP AND PRUNE
void Physics::collideTestWithSprites(Game* game, CollidableObject* c, list<Collision*> *collisions)
{
SpriteManager *sm = game->getGSM()->getSpriteManager();
AnimatedSprite* player = sm->getPlayer();
if(c != player)
{
if(player->isCurrentlyCollidable() == true)
{
if(willObjectsCollide(player, c) == true)
{
Collision* currentCollision = collisionStack[collisionStackCounter];
collisionStackCounter --;
currentCollision->setCO1(player);
currentCollision->setCO2(c);
currentCollision->calculateTimes();
if(currentCollision->getTOC() > 0 && currentCollision->getTOC() <= 1)
{
collisions->push_back(currentCollision);
}
else
{
collisionStackCounter ++;
collisionStack[collisionStackCounter] = currentCollision;
}
}//end if
}//end if
}//end if
else
{
list<Bot*>::iterator botIterator = sm->getBotsIterator();
while (botIterator != sm->getEndOfBotsIterator())
{
Bot *bot = (*botIterator);
if(c != bot && bot->isCurrentlyCollidable() == true)
{
if(willObjectsCollide(c, bot) == true)
{
Collision* currentCollision = collisionStack[collisionStackCounter];
collisionStackCounter --;
currentCollision->setCO1(c);
currentCollision->setCO2(bot);
currentCollision->calculateTimes();
if(currentCollision->getTOC() > 0 && currentCollision->getTOC() <= 1)
{
collisions->push_back(currentCollision);
}
else
{
collisionStackCounter ++;
collisionStack[collisionStackCounter] = currentCollision;
}
}//end if
}//end if
botIterator++;
}//end while
}
/*Collision* currentCollision = collisionStack[collisionStackCounter];
collisionStackCounter --;
currentCollision->setCO1(c);
currentCollision->setCO2(tileCO);
currentCollision->calculateTimes();
collisions->push_back(currentCollision);*/
}