本文整理汇总了C++中Collision::isCollisionWithTile方法的典型用法代码示例。如果您正苦于以下问题:C++ Collision::isCollisionWithTile方法的具体用法?C++ Collision::isCollisionWithTile怎么用?C++ Collision::isCollisionWithTile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collision
的用法示例。
在下文中一共展示了Collision::isCollisionWithTile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeActiveCOCollisions
/*
When we resolve a collision involving a sprite other collisions
involving it are then obsolete, so this method removes them.
*/
void Physics::removeActiveCOCollisions(CollidableObject *co)
{
list<Collision*>::iterator coIt = activeCollisions.begin();
while (coIt != activeCollisions.end())
{
// WE'LL NEED THIS TO REMOVE THE ELEMENT
list<Collision*>::iterator tempIt = coIt;
// BUT WE'LL MOVE THE ITERATOR ALONG NOW FOR THE NEXT LOOP
coIt++;
// GET THE COLLISION WE MAY NEED TO REMOVE
if (tempIt != activeCollisions.end())
{
Collision *c = (*tempIt);
// AND TEST IT
if ((co == c->getCO1()) || (co == c->getCO2()))
{
// RECYCLE THE COLLIDABLE OBJECTS IF NECESSARY
if (c->isCollisionWithTile())
{
recycledCollidableObjectsList.push_back(c->getCO2());
}
// PUT IT BACK IN THE RECYCLING BIN
recycledCollisions.push_back(c);
// AND REMOVE IT FROM THE LIST
activeCollisions.erase(tempIt);
}
}
}
}
示例2: update
//.........这里部分代码省略.........
// NOTE THAT I'M JUST EMPLOYING THE STL'S List
// CLASS' SORT METHOD BY PROVIDING MY OWN
// MEANS FOR COMPARING Collision OBJECTS
activeCollisions.sort(CollisionComparitor());
// GET FIRST COLLISION - NOTE THAT WE HAVE THE COLLISIONS SORTED
// IN DESCENDING ORDER, SO TO TAKE THE EARLIEST ONE, WE REMOVE IT
// FOM THE BACK OF THE SORTED LIST
Collision *earliestCollision = activeCollisions.back();
activeCollisions.pop_back();
float collisionTime = earliestCollision->getTimeOfCollision();
// MOVE ALL SPRITES UP TO TIME OF FIRST COLLISION USING
// APPROPRIATELY SCALED VELOCITIES
moveAllSpritesUpToBufferedTimeOfCollision(earliestCollision);
// AND ADVANCE COLLISION TIME
currentCollisionTime = collisionTime;
// AND UPDATE THE VELOCITIES OF THE SPRITE(S) INVOLVED IN THE COLLISION
performCollisionResponse(earliestCollision);
// EXECUTE COLLISION EVENT CODE
// TEST TO SEE TYPES OF OBJECTS AND APPROPRIATE RESPONSE
// ACCORDING TO CUSTOMIZED COLLISION EVENT HANDLER
collisionListener->respondToCollision(game, earliestCollision);
// FOR THE TWO OBJECTS INVOLVED IN THE COLLISION
// REMOVE ALL OTHER COLLISIONS INVOLVING THEM
// SINCE THEY ARE NOW OBSOLETE. THE REASON BEING
// THE OBJECT COLLISION NOW LIKELY HAS A
// DIFFERENT VECTOR
// UPDATE THEIR SWEPT SHAPES
// TEST THEM AGAINST TILES AGAIN
CollidableObject *co1 = earliestCollision->getCO1();
CollidableObject *co2 = earliestCollision->getCO2();
removeActiveCOCollisions(co1);
co1->updateSweptShape(1.0f - currentCollisionTime);
getAllTileCollisionsForAGivenSprite(world, co1, 1.0f - currentCollisionTime);
// ONLY DO IT FOR THE SECOND ONE IF IT'S NOT A TILE
if (!earliestCollision->isCollisionWithTile())
{
removeActiveCOCollisions(co2);
co2->updateSweptShape(1.0f - currentCollisionTime);
getAllTileCollisionsForAGivenSprite(world, co2, 1.0f - currentCollisionTime);
}
else
{
spriteToTileCollisionsThisFrame[co1].insert(earliestCollision->getTile());
recycledCollidableObjectsList.push_back(co2);
}
// NOW WE NEED TO SEE IF THE SPRITES INVOLVED IN THE JUST
// RESOLVED COLLISION ARE GOING TO BE INVOLVED IN ANY MORE
// WITH OTHER SPRITES BUT WE DON'T WANT TO CHECK ALL OF THEM,
// WE ONLY WANT TO CHECK NEIGHBORS, BUT FIRST WE HAVE TO
// MAKE SURE THE SPRITE(S) THAT WE JUST RESOLVED ARE IN THEIR
// PROPER SWEPT SHAPE LOCATIONS WITHOUT HAVING TO RESORT EVERTYHING
// IF IT WAS ONLY ONE SPRITE WITH A TILE THIS IS EASY TO DO
if (earliestCollision->isCollisionWithTile())
{
reorderCollidableObject(co1);
}
// YOU'LL HAVE TO WORRY ABOUT REORDERING STUFF FOR COLLISIONS
// BETWEEN TWO SPRITES
// NOW TEST NEIGHBORS OF SPRITES INVOLVED IN RESOLVED COLLISION
// AGAINST NEIGHBORS IN SWEPT SHAPE DATA STRUCTURES. YOU'LL HAVE
// TO FIGURE OUT HOW TO DO THIS AND HOW TO RESOLVE SUCH COLLISIONS
// RECYCLE THE COLLISION SINCE WE'RE NOW DONE WITH IT
recycledCollisions.push_back(earliestCollision);
}
// APPLY THE REMAINING TIME TO MOVE THE SPRITES. NOTE THAT
// THIS IS ACTUALLY A VERY RISKY, TRICKY STEP BECAUSE IT COULD
// MOVE OBJECTS ALMOST TO THE POINT OF COLLISION, WHICH MAY THEN
// BE DETECTED ALMOST AT TIME 0 NEXT FRAME. THERE ARE OTHER TRICKY
// ISSUES RELATED TO OUR BUFFER AS WELL, SO WE CHEAT A LITTLE HERE
// AND SCALE THE TIME REMAINING DOWN A LITTE
if (currentCollisionTime < 1.0f)
moveAllSpritesToEndOfFrame();
// INIT TILE COLLISION INFO
// SET ON TILE LAST FRAME USING ON TILE THIS FRAME
// SET ON TILE THIS FRAME TO FALSE
spritesIt = sortedSweptShapes[LEFT_EDGE]->begin();
while (spritesIt != sortedSweptShapes[LEFT_EDGE]->end())
{
CollidableObject *sprite = (*spritesIt);
sprite->advanceOnTileStatus();
spritesIt++;
}
// WE'RE NOT GOING TO ALLOW MULTIPLE COLLISIONS TO HAPPEN IN A FRAME
// BETWEEN THE SAME TWO OBJECTS
spriteToTileCollisionsThisFrame.clear();
}