本文整理汇总了C++中PhysicalProperties::applyAcceleration方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicalProperties::applyAcceleration方法的具体用法?C++ PhysicalProperties::applyAcceleration怎么用?C++ PhysicalProperties::applyAcceleration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicalProperties
的用法示例。
在下文中一共展示了PhysicalProperties::applyAcceleration方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: prepSpriteForCollisionTesting
/*
Done each frame before collision testing, it updates the "on tile" states
and then applies acceleration and gravity to the sprite's velocity. Then it
initializes the swept shape for the sprite.
*/
void Physics::prepSpriteForCollisionTesting(World *world, CollidableObject *sprite)
{
// THIS GUY HAS ALL THE PHYSICS STUFF FOR THE SPRITE
PhysicalProperties *pp = sprite->getPhysicalProperties();
// APPLY ACCELERATION
pp->applyAcceleration();
// APPLY GRAVITY
pp->incVelocity(0.0f, gravity);
// NOW, IF THE SPRITE WAS ON A TILE LAST FRAME LOOK AHEAD
// TO SEE IF IT IS ON A TILE NOW. IF IT IS, UNDO GRAVITY.
// THIS HELPS US AVOID SOME PROBLEMS
if (sprite->wasOnTileLastFrame())
{
// FIRST MAKE SURE IT'S SWEPT SHAPE ACCOUNTS FOR GRAVITY
sprite->updateSweptShape(1.0f);
// WE'LL LOOK THROUGH THE COLLIDABLE LAYERS
vector<WorldLayer*> *layers = world->getLayers();
for (int i = 0; i < world->getNumLayers(); i++)
{
WorldLayer *layer = layers->at(i);
if (layer->hasCollidableTiles())
{
bool test = layer->willSpriteCollideOnTile(this, sprite);
if (test)
{
sprite->setOnTileThisFrame(true);
pp->setVelocity(pp->getVelocityX(), 0.0f);
sprite->updateSweptShape(1.0f);
return;
}
else
cout << "What Happened?";
}
}
}
// INIT THE SWEPT SHAPE USING THE NEWLY APPLIED
// VELOCITY. NOTE THAT 100% OF THE FRAME TIME
// IS LEFT, DENOTED BY 1.0f
sprite->updateSweptShape(1.0f);
}