本文整理汇总了C++中PhysicalProperties::incVelocity方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicalProperties::incVelocity方法的具体用法?C++ PhysicalProperties::incVelocity怎么用?C++ PhysicalProperties::incVelocity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicalProperties
的用法示例。
在下文中一共展示了PhysicalProperties::incVelocity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: 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);
//.........这里部分代码省略.........