本文整理汇总了C++中PhysicalProperties::getVelocityY方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicalProperties::getVelocityY方法的具体用法?C++ PhysicalProperties::getVelocityY怎么用?C++ PhysicalProperties::getVelocityY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicalProperties
的用法示例。
在下文中一共展示了PhysicalProperties::getVelocityY方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: willObjectsCollide
bool Physics::willObjectsCollide(CollidableObject* coA, CollidableObject* coB)
{
PhysicalProperties* pp = coA->getPhysicalProperties();
BoundingVolume* bv = coA->getBoundingVolume();
float widthA = bv->getWidth();
float heightA = bv->getHeight();
float xA = pp->getX() + bv->getX();
float yA = pp->getY() + bv->getY();
float velXA = pp->getVelocityX();
float velYA = pp->getVelocityY();
float minXA = xA-(widthA/2);
float maxXA = xA+(widthA/2);
float minYA = yA-(heightA/2);
float maxYA = yA+(heightA/2);
if(velXA >= 0)
maxXA += velXA;
if(velXA < 0)
minXA += velXA;
if(velYA >= 0)
maxYA += velYA;
if(velYA < 0)
minYA += velYA;
pp = coB->getPhysicalProperties();
bv = coB->getBoundingVolume();
float widthB = bv->getWidth();
float heightB = bv->getHeight();
float xB = pp->getX() + bv->getX();
float yB = pp->getY() + bv->getY();
float velXB = pp->getVelocityX();
float velYB = pp->getVelocityY();
float minXB = xB-(widthB/2);
float maxXB = xB+(widthB/2);
float minYB = yB-(heightB/2);
float maxYB = yB+(heightB/2);
if(velXB >= 0)
maxXB += velXB;
if(velXB < 0)
minXB += velXB;
if(velYB >= 0)
maxYB += velYB;
if(velYB < 0)
minYB += velYB;
if( !(maxXB < minXA || minXB > maxXA || maxYB < minYA || minYB > maxYA))
return true;
return false;
}
示例2: update
/*
update - This method should be called once per frame. It updates
both the sprites and the game world. Note that even though the game
world is for static data, should the user wish to put anything dynamic
there (like a non-collidable moving layer), the updateWorld method
is called.
*/
void GameStateManager::update(Game *game)
{
game->getGameRules()->spawnEnemies(game);
spriteManager->update(game);
world.update(game);
physics.update(game);
AnimatedSprite *p = spriteManager->getPlayer();
PhysicalProperties *pp = p->getPhysicalProperties();
float pVelX = pp->getVelocityX();
float pVelY = pp->getVelocityY();
//VIEWPORT SCOPING
/*Viewport *vp = game->getGUI()->getViewport();
if(pVelX < 0
&& (pp->round(pp->getX() - vp->getViewportX())) < vp->getViewportWidth()/3)
{
vp->setScrollSpeedX(pVelX);
if(vp->getViewportX() == 0)
vp->setScrollSpeedX(0);
}
else if(pVelX > 0
&& (pp->round(pp->getX() - vp->getViewportX())) > (vp->getViewportWidth()/3*2))
{
vp->setScrollSpeedX(pVelX);
if(vp->getViewportX()+vp->getViewportWidth() == world.getWorldWidth())
vp->setScrollSpeedX(0);
}
else
{
vp->setScrollSpeedX(0);
}
if(pVelY < 0
&& (pp->round(pp->getY() - vp->getViewportY())) < vp->getViewportHeight()/3)
{
vp->setScrollSpeedY(pVelY);
if(vp->getViewportY() == 0)
vp->setScrollSpeedY(0);
}
else if(pVelY > 0
&& (pp->round(pp->getY() - vp->getViewportY())) > (vp->getViewportHeight()/3*2))
{
vp->setScrollSpeedY(pVelY);
if(vp->getViewportY()+vp->getViewportHeight() == world.getWorldHeight())
vp->setScrollSpeedY(0);
}
else
{
vp->setScrollSpeedY(0);
}
vp->moveViewport( vp->getScrollSpeedX(),
vp->getScrollSpeedY(),
world.getWorldWidth(),
world.getWorldHeight());*/
}
示例3: think
/*
think - called once per frame, this is where the bot performs its
decision-making. Note that we might not actually do any thinking each
frame, depending on the value of cyclesRemainingBeforeThinking.
*/
void BackAndForthBot::think(Game *game)
{
// EACH FRAME WE'LL TEST THIS BOT TO SEE IF WE NEED
// TO PICK A DIFFERENT DIRECTION TO FLOAT IN
PhysicalProperties* pp = &(this->pp);
if(!dead)
{
if(pp->getVelocityX() == 0)
{
pp->setVelocity(vel, pp->getVelocityY());
}
if (cyclesRemainingBeforeChange == 0)
{
vel *= -1;
pp->setVelocity(vel, pp->getVelocityY());
if(pp->isOrientedRight())
{
this->setCurrentState(L"WALKL_STATE");
pp->setOrientedLeft();
}
else
{
this->setCurrentState(L"WALK_STATE");
pp->setOrientedRight();
}
cyclesRemainingBeforeChange = pathSize;
}
else
cyclesRemainingBeforeChange--;
}
else
{
wstring curState = this->getCurrentState();
pp->setVelocity(0,pp->getVelocityY());
int lastFrame = this->getSpriteType()->getSequenceSize(curState)-2;
if(this->getFrameIndex() == lastFrame)
{
game->getGSM()->getSpriteManager()->removeBot(this);
}
}
}
示例4: handleKeyEvents
/*
handleKeyEvent - this method handles all keyboard interactions. Note that every frame this method
gets called and it can respond to key interactions in any custom way. Ask the GameInput class for
key states since the last frame, which can allow us to respond to key presses, including when keys
are held down for multiple frames.
*/
void SoSKeyEventHandler::handleKeyEvents(Game *game)
{
// WE CAN QUERY INPUT TO SEE WHAT WAS PRESSED
GameInput *input = game->getInput();
// LET'S GET THE PLAYER'S PHYSICAL PROPERTIES, IN CASE WE WANT TO CHANGE THEM
GameStateManager *gsm = game->getGSM();
AnimatedSprite *player = gsm->getSpriteManager()->getPlayer();
PhysicalProperties *pp = player->getPhysicalProperties();
if(gsm->isAtSplashScreen())
{
if(input->isKeyDown(ENTER_KEY))
{
gsm->goToMainMenu();
}
}
// IF THE GAME IS IN PROGRESS
if (gsm->isGameInProgress())
{
// CHECK FOR WASD KEYS FOR MOVEMENT
int incX = 0;
int incY = 0;
bool movingLR = false;
bool attacking = false;
if(!pp->isStunned())
{
if(input->isKeyDown(SPACE_KEY))
{
attacking = true;
if(input->isKeyDownForFirstTime(SPACE_KEY))
{
player->setCurrentState(L"ATTACK_STATE");
if(!pp->isOrientedRight())
player->setCurrentState(L"ATTACKL_STATE");
}
}
// WASD AND DIRECTION KEY PRESSES WILL CONTROL THE PLAYER,
// SO WE'LL UPDATE THE PLAYER VELOCITY WHEN THESE KEYS ARE
// PRESSED, THAT WAY PHYSICS CAN CORRECT AS NEEDED
float vX = pp->getVelocityX();
float vY = pp->getVelocityY();
if (input->isKeyDown(A_KEY) || input->isKeyDown(LEFT_KEY))
{
movingLR = true;
pp->setOrientedLeft();
vX = -PLAYER_SPEED;
if (vY == 0 && player->getCurrentState().compare(L"LEFT_STATE") != 0)
player->setCurrentState(L"LEFT_STATE");
else if(vY != 0 && player->getCurrentState().compare(L"JUMPL_STATE") != 0)
player->setCurrentState(L"JUMPL_STATE");
}
if (input->isKeyDown(D_KEY) || input->isKeyDown(RIGHT_KEY))
{
movingLR = true;
pp->setOrientedRight();
vX = PLAYER_SPEED;
if (vY == 0 && player->getCurrentState().compare(L"RIGHT_STATE") != 0)
player->setCurrentState(L"RIGHT_STATE");
else if(vY != 0 && player->getCurrentState().compare(L"JUMP_STATE") != 0)
player->setCurrentState(L"JUMP_STATE");
}
/*if (input->isKeyDown(S_KEY) || input->isKeyDown(DOWN_KEY))
{
vY = PLAYER_SPEED;
}*/
if (input->isKeyDown(W_KEY) || input->isKeyDown(UP_KEY))
{
if ((input->isKeyDownForFirstTime(W_KEY) || input->isKeyDownForFirstTime(UP_KEY))
&& pp->hasDoubleJumped() == false)
{
if(pp->hasJumped() == true)
pp->setDoubleJumped(true);
pp->setJumped(true);
vY = -PLAYER_SPEED;
player->setCurrentState(L"JUMP_STATE");
if(vX < 0)
player->setCurrentState(L"JUMPL_STATE");
}
}
if(!movingLR)
//.........这里部分代码省略.........
示例5: update
//.........这里部分代码省略.........
//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);
pp = player->getPhysicalProperties();
pp->setPosition(pp->getX() + (pp->getVelocityX()*(colTime-timer)),pp->getY() + (pp->getVelocityY()*(colTime-timer)));
botIterator = sm->getBotsIterator();
while (botIterator != sm->getEndOfBotsIterator())
{
Bot *bot = (*botIterator);
pp = bot->getPhysicalProperties();
pp->setPosition(pp->getX() + (pp->getVelocityX()*(colTime-timer)), pp->getY() + (pp->getVelocityY()*(colTime-timer)));
botIterator++;
}
gsm->updateViewport(game, colTime-timer);
resolveCollision(game, currentCollision);
gR->gameSpecificResolve(game, currentCollision);
boolean deleteLast = false;
list<Collision*>::iterator cIterator = collisions.begin();
list<Collision*>::iterator lastIterator;
while(cIterator != collisions.end())
{
if(deleteLast == true)
{
collisions.erase(lastIterator);
}
deleteLast = false;
Collision* check = (*cIterator);
if(check->contains(co1) || check->contains(co2))
{
CollidableObject* checkStatic = check->getCO2();
if(checkStatic->isStaticObject())
{
coStackCounter ++;
coStack[coStackCounter] = checkStatic;
示例6: resolveCollision
void Physics::resolveCollision(Game* game, Collision* currentCollision)
{
CollidableObject* co1 = currentCollision->getCO1();
CollidableObject* co2 = currentCollision->getCO2();
PhysicalProperties* pp;
BoundingVolume* bv;
AnimatedSprite* player = game->getGSM()->getSpriteManager()->getPlayer();
if(co2->isStaticObject() == true)
{
pp = co2->getPhysicalProperties();
bv = co2->getBoundingVolume();
float tX = pp->getX();
float tY = pp->getY();
float tXR = tX + bv->getWidth();
float tYB = tY + bv->getHeight();
pp = co1->getPhysicalProperties();
bv = co1->getBoundingVolume();
float x = pp->getX() + bv->getX() - (bv->getWidth()/2);
float y = pp->getY() + bv->getY() - (bv->getHeight()/2);
float xR = x+bv->getWidth();
float yB = y+bv->getHeight();
//pp->setVelocity(0, 0);
/*if(x < tX)
pp->setX(pp->getX() - 0.1);
if(x > tX)
pp->setX(pp->getX() + 0.1);*/
if(x >= tXR)
{
pp->setX(pp->getX() + 0.1);
pp->setVelocity(0, pp->getVelocityY());
}
if(xR <= tX)
{
pp->setX(pp->getX() - 0.1);
pp->setVelocity(0, pp->getVelocityY());
}
if(y >= tYB)
{
pp->setY(pp->getY() + 0.1);
pp->setVelocity(pp->getVelocityX(), 0);
}
if(yB <= tY)
{
pp->setY(pp->getY() - 0.1);
if(co1 == player)
{
pp->setJumped(false);
pp->setDoubleJumped(false);
pp->setStunned(false);
}
pp->setVelocity(pp->getVelocityX(), 0);
}
//if(currentCollision->getTOC() == currentCollision->getSYC())
//{
// /*if(pp->getVelocityY() < 0)
// {
// pp->setY(pp->getY() + 0.1);
// }
// else
// {
// pp->setY(pp->getY() - 0.1);
// if(co1 == player)
// {
// pp->setJumped(false);s
// pp->setDoubleJumped(false);
// if(player->getCurrentState().compare(L"JUMP_STATE") == 0
// || player->getCurrentState().compare(L"JUMPL_STATE") == 0)
// {
// player->setCurrentState(L"IDLE_STATE");
// }
// }
// }*/
// if(y < tY)
// {
// pp->setY(pp->getY() - 0.1);
// if(co1 == player)
// {
// pp->setJumped(false);
// pp->setDoubleJumped(false);
// /*if(player->getCurrentState().compare(L"JUMP_STATE") == 0
// || player->getCurrentState().compare(L"JUMPL_STATE") == 0)
// {
// player->setCurrentState(L"IDLE_STATE");
// }*/
// }
// }
// if(y > tY)
// {
// pp->setY(pp->getY() + 0.1);
//
// }
// pp->setVelocity(pp->getVelocityX(), 0);
//
//
//}
//else if(currentCollision->getTOC() == currentCollision->getSXC())
//.........这里部分代码省略.........
示例7: collideTestWithTiles
void Physics::collideTestWithTiles(CollidableObject *c,TiledLayer *tL, list<Collision*> *collisions)
{
BoundingVolume *bv = c->getBoundingVolume();
float toRight= bv->getWidth()/2;
float toBottom = bv->getHeight()/2;
PhysicalProperties *pp = c->getPhysicalProperties();
float x = pp->getX()+bv->getX();
float y = pp->getY()+bv->getY();
float xVel = pp->getVelocityX();
float yVel = pp->getVelocityY();
float minX = x - toRight;
float maxX = x + toRight;
float minY = y - toBottom;
float maxY = y + toBottom;
if(xVel > 0)
maxX += xVel;
else
minX += xVel;
if(yVel > 0)
maxY += yVel;
else
minY += yVel;
int tW = tL->getTileWidth();
int tH = tL->getTileHeight();
int firstCol = minX/tW;
int lastCol = maxX/tW;
int firstRow = minY/tH;
int lastRow = maxY/tH;
if(firstCol < 0)
firstCol = 0;
if(firstRow < 0)
firstRow = 0;
if(lastCol >= tL->getColumns())
lastCol = tL->getColumns() - 1;
if(lastRow >= tL->getRows())
lastRow = tL->getRows() - 1;
for(int i = firstRow; i <= lastRow; i++)
{
for(int j = firstCol; j <= lastCol; j++)
{
Tile* current = tL->getTile(i,j);
if(current->collidable == true)
{
if( !( (i+1)*tH < minY || i*tH > maxY || (j+1)*tW < minX || j*tW > maxX) )
{
CollidableObject* tileCO = coStack[coStackCounter];
coStackCounter --;
BoundingVolume *bv = tileCO->getBoundingVolume();
bv->setWidth(tW);
bv->setHeight(tH);
bv->setX(tW/2);
bv->setY(tW/2);
pp = tileCO->getPhysicalProperties();
pp->setPosition(j*tW,i*tH);
/*
Collision* currentCollision = collisionStack.top();
collisionStack.pop();*/
Collision* currentCollision = collisionStack[collisionStackCounter];
collisionStackCounter --;
currentCollision->setCO1(c);
currentCollision->setCO2(tileCO);
currentCollision->calculateTimes();
collisions->push_back(currentCollision);
}
}
}
}
}
示例8: getCollisionsSpriteSprite
void Physics::getCollisionsSpriteSprite( World *world,
CollidableObject *spriteA,
CollidableObject *spriteB,
float percentageOfFrameRemaining)
{
//vector<WorldLayer*> *layers = world->getLayers();
AABB *boundingVolumeA = spriteA->getBoundingVolume();
AABB *boundingVolumeB = spriteB->getBoundingVolume();
PhysicalProperties *ppA = spriteA->getPhysicalProperties();
PhysicalProperties *ppB = spriteB->getPhysicalProperties();
int centerXA = boundingVolumeA->getCenterX();
int centerXB = boundingVolumeB->getCenterX();
int centerYA = boundingVolumeA->getCenterY();
int centerYB = boundingVolumeB->getCenterY();
int widthA = boundingVolumeA->getWidth();
int widthB = boundingVolumeB->getWidth();
int heightA = boundingVolumeA->getHeight();
int heightB = boundingVolumeB->getHeight();
int vxA = ppA->getVelocityX();
int vxB = ppB->getVelocityX();
int vyA = ppA->getVelocityY();
int vyB = ppB->getVelocityY();
// A - B
if ((centerXB - (widthB/2)) > (centerXA + (widthA/2)))
{
//if(!((vxA - vxB) == 0)) {
// if(boundingVolumeA->overlapsX(boundingVolumeB)){
if(!((vxA - vxB) == 0)) {
int tx_first_contact = abs(((centerXB - (widthB/2)) - (centerXA + (widthA/2)))/(vxA - vxB));
int tx_last_contact = abs(((centerXB + (widthB/2)) - (centerXA - (widthA/2)))/(vxA - vxB));
if(tx_first_contact > percentageOfFrameRemaining)
{
//there`s no collision
}
else
{
if(!(vyA - vyB) == 0)
{
//there`s contact on X axis, so let`s see if there`s contact on y axis
int ty_first_contact = abs(((centerYB - (heightB/2)) - (centerYA + (heightA/2)))/(vyA - vyB));
//int ty_first_contact = boundingVolumeA->overlapsY(boundingVolumeB);
int ty_last_contact = abs(((centerYB + (heightB/2)) - (centerYA - (heightA/2)))/(vyA - vyB));
if(ty_first_contact > percentageOfFrameRemaining)
{
//there`s no collision
}
else
{
//there`s collision!
//add collision to vector
addCollisionSpriteSprite(spriteA, spriteB);
}
}
else
{
//none of them are not going anywhere up, so they must collide on x axis
//if they collide on y
//if(((centerYB + heightB/2) - (centerYA - heightA/2)) >= 0)
if(boundingVolumeA->overlapsY(boundingVolumeB))
{addCollisionSpriteSprite(spriteA, spriteB);}
}
// }
}
}
else
{
//the situation here is kind of special
//they could be stopped in X, or they could be walking in the same velocity
//in the second situation, we are cool because they wouldn`t collide anyway
//in the firt situation, they could colide (one on top of the other)
//because of this, we have to make sure that one is on top of the other
//and that they can collide on y axis
//boundingVolumeB->setWidth(boundingVolumeB->getWidth() *2);
if(boundingVolumeA->myOverlapsX(boundingVolumeB))// && !(boundingVolumeA->overlapsY(boundingVolumeB)))
{
//boundingVolumeB->setWidth(boundingVolumeB->getWidth()/2);
addCollisionSpriteSprite(spriteA, spriteB);
}
}
}
// B - A
else
{
if(!((vxB - vxA) == 0)) {
//.........这里部分代码省略.........