本文整理汇总了C++中Collision::setCollisionWithTile方法的典型用法代码示例。如果您正苦于以下问题:C++ Collision::setCollisionWithTile方法的具体用法?C++ Collision::setCollisionWithTile怎么用?C++ Collision::setCollisionWithTile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collision
的用法示例。
在下文中一共展示了Collision::setCollisionWithTile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addCollisionSpriteSprite
void Physics::addCollisionSpriteSprite(CollidableObject *dynamicObjectA, CollidableObject *dynamicObjectB)
{
// IF WE'VE ALREADY HANDLED A COLLISION BETWEEN THESE TWO OBJECTS THIS
// FRAME THEN IGNORE IT
//PAULO- MAYBE IMPORTANT***********************
/*set<CollidableObject*> doSprite = spriteToSpriteCollisionsThisFrame[dynamicObjectB];
if (doSprite.find(dynamicObjectB) != doSprite.end())
return;*/
// FIRST WE'RE GOING TO DO A MORE NARROW CHECK TO SEE IF THE dynamicObject
// REALLY DOES COLLIDE WITH THE TILE. TO DO SO WE'LL CALCULATE THE TIME
// OF COLLISION. IF IT HAPPENS AFTER THIS FRAME IS OVER (> 1), THEN WE
// WILL IGNORE IT
unsigned int co1Edge, co2Edge;
float timeUntilCollision = calculateTimeUntilCollision(dynamicObjectA,dynamicObjectB, co1Edge, co2Edge, 0.0f);
if (timeUntilCollision > 1.0f)
return;
//// NOW LET'S MAKE A COLLISION FOR THE SPRITE-SPRITE
Collision *collisionToAdd = recycledCollisions.back();
collisionToAdd->setCO1(dynamicObjectA);
collisionToAdd->setCO2(dynamicObjectB);
collisionToAdd->setCO1Edge(co1Edge);
collisionToAdd->setCO2Edge(co2Edge);
collisionToAdd->setCollisionWithSprite(true);
collisionToAdd->setCollisionWithTile(false);
collisionToAdd->setTimeOfCollision(timeUntilCollision);
//collisionToAdd->setTile(tile);
recycledCollisions.pop_back();
activeCollisions.push_back(collisionToAdd);
}
示例2: addTileCollision
/*
Called when a collision is detected between a world tile
and a sprite, this records that collision so that it
can be resolved later if needed.
*/
void Physics::addTileCollision(CollidableObject *dynamicObject, Tile *tile, float tileX, float tileY, float tileWidth, float tileHeight)
{
// IF WE'VE ALREADY HANDLED A COLLISION BETWEEN THESE TWO OBJECTS THIS
// FRAME THEN IGNORE IT
set<Tile*> doTiles = spriteToTileCollisionsThisFrame[dynamicObject];
if (doTiles.find(tile) != doTiles.end())
return;
// GET A DUMMY COLLIABLE OBJECT TO USE FOR THE TILE
CollidableObject *tileInfoForCollision = recycledCollidableObjectsList.back();
// FILL IT WITH DATA
AABB *bv = tileInfoForCollision->getBoundingVolume();
bv->setCenterX(tileX + (tileWidth/2));
bv->setCenterY(tileY + (tileHeight/2));
bv->setWidth(tileWidth);
bv->setHeight(tileHeight);
// FIRST WE'RE GOING TO DO A MORE NARROW CHECK TO SEE IF THE dynamicObject
// REALLY DOES COLLIDE WITH THE TILE. TO DO SO WE'LL CALCULATE THE TIME
// OF COLLISION. IF IT HAPPENS AFTER THIS FRAME IS OVER (> 1), THEN WE
// WILL IGNORE IT
unsigned int co1Edge, co2Edge;
float timeUntilCollision = calculateTimeUntilCollision(dynamicObject, tileInfoForCollision, co1Edge, co2Edge, 0.0f);
if (timeUntilCollision > 1.0f)
return;
// IF IT MADE IT HERE, A COLLISION IS HAPPENING
// AND REMOVE IT FROM THE RECYCLING CENTER
recycledCollidableObjectsList.pop_back();
// NOW LET'S MAKE A COLLISION FOR THE TILE-SPRITE
Collision *collisionToAdd = recycledCollisions.back();
collisionToAdd->setCO1(dynamicObject);
collisionToAdd->setCO2(tileInfoForCollision);
collisionToAdd->setCO1Edge(co1Edge);
collisionToAdd->setCO2Edge(co2Edge);
collisionToAdd->setCollisionWithTile(true);
collisionToAdd->setTimeOfCollision(timeUntilCollision);
collisionToAdd->setTile(tile);
recycledCollisions.pop_back();
activeCollisions.push_back(collisionToAdd);
}