本文整理汇总了C++中AnimatedSprite::setCurrentState方法的典型用法代码示例。如果您正苦于以下问题:C++ AnimatedSprite::setCurrentState方法的具体用法?C++ AnimatedSprite::setCurrentState怎么用?C++ AnimatedSprite::setCurrentState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnimatedSprite
的用法示例。
在下文中一共展示了AnimatedSprite::setCurrentState方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: respondToCollision
void BalloonEscapeCollisionListener::respondToCollision(Game *game, Collision *collision)
{
// NOTE FROM THE COLLIDABLE OBJECTS, WHICH ARE IN THE COLLISION,
// WE CAN CHECK AND SEE ON WHICH SIDE THE COLLISION HAPPENED AND
// CHANGE SOME APPROPRIATE STATE ACCORDINGLY
GameStateManager *gsm = game->getGSM();
AnimatedSprite *player = gsm->getSpriteManager()->getPlayer();
PhysicalProperties *pp = player->getPhysicalProperties();
//AnimatedSprite *bot = collision
CollidableObject *sprite2 = collision->getCO2();
PhysicalProperties *pp2 = sprite2->getPhysicalProperties();
AnimatedSprite *bot = (AnimatedSprite*)sprite2;
if (!collision->isCollisionWithTile() && player->getCurrentState() != L"DYING")
{
CollidableObject *sprite = collision->getCO1();
if (sprite2->getPhysicalProperties()->getZ() == 1.0f) {
bot = (AnimatedSprite*)sprite;
pp = sprite2->getPhysicalProperties();
pp2 = sprite->getPhysicalProperties();
sprite = collision->getCO2();
sprite2 = collision->getCO1();
if (sprite->getCollisionEdge() == BOTTOM_EDGE)
{
bot->setCurrentState(L"DYING");
pp2->setVelocity(0.0f, 0.0f);
pp2->setAccelerationX(0);
pp2->setAccelerationY(0);
// ENEMY IS DEAD - WE SHOULD PLAY A DEATH ANIMATION
// AND MARK IT FOR REMOVAL
}
else if (bot->getCurrentState() != L"DYING")
{
if (pp->getDelay() == 0) {
if (pp->getHP() == 10 ) {
//lives->setCurrentState(L"TWO");
if(deadonce == true)
//lives->setCurrentState(L"ONE");
player->setCurrentState(L"DYING");
pp->setDelay(90);
pp->setVelocity(0.0f, 0.0f);
pp->setAccelerationX(0);
pp->setAccelerationY(0);
deadonce=true;
}
else {
pp->setDelay(90);
pp->setHP(pp->getHP()-10);
SpriteManager *spriteManager = gsm->getSpriteManager();
AnimatedSpriteType *yellowman = spriteManager->getSpriteType(3);
player->setSpriteType(yellowman);
}
}
// PLAYER IS DEAD - WE SHOULD PLAY A DEATH ANIMATION
// AND MARK IT FOR REMOVAL/RESPAWN/RESTART GAME, WHATEVER
// THE DEMANDS OF THE GAME ARE
}
}
else if(sprite->getPhysicalProperties()->getZ() == 1.0f) {
PhysicalProperties *pp = sprite->getPhysicalProperties();
if (sprite->getCollisionEdge() == BOTTOM_EDGE)
{
bot->setCurrentState(L"DYING");
pp2->setVelocity(0.0f, 0.0f);
pp2->setAccelerationX(0);
pp2->setAccelerationY(0);
// ENEMY IS DEAD - WE SHOULD PLAY A DEATH ANIMATION
// AND MARK IT FOR REMOVAL
}
else if (bot->getCurrentState() != L"DYING")
{
if (pp->getDelay() == 0) {
if (pp->getHP() == 10 ) {
//lives->setCurrentState(L"TWO");
if(deadonce == true)
//lives->setCurrentState(L"ONE");
player->setCurrentState(L"DYING");
pp->setDelay(90);
pp->setVelocity(0.0f, 0.0f);
pp->setAccelerationX(0);
pp->setAccelerationY(0);
deadonce=true;
}
else {
pp->setDelay(90);
pp->setHP(pp->getHP()-10);
SpriteManager *spriteManager = gsm->getSpriteManager();
AnimatedSpriteType *yellowman = spriteManager->getSpriteType(3);
player->setSpriteType(yellowman);
}
}
//.........这里部分代码省略.........
示例2: 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)
//.........这里部分代码省略.........
示例3: 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 BugsKeyEventHandler::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();
Viewport *viewport = game->getGUI()->getViewport();
// IF THE GAME IS IN PROGRESS
if (gsm->isGameInProgress())
{
if (input->isKeyDownForFirstTime(D_KEY))
{
viewport->toggleDebugView();
game->getGraphics()->toggleDebugTextShouldBeRendered();
}
if (input->isKeyDownForFirstTime(L_KEY))
{
game->getGraphics()->togglePathfindingGridShouldBeRendered();
}
if (input->isKeyDownForFirstTime(F_KEY))
{
game->getGraphics()->togglePathfindingPathShouldBeRendered();
}
if (input->isKeyDownForFirstTime(R_KEY))
{
if (wcscmp(player->getCurrentState().c_str(), L"RUNNING") == 0)
player->setCurrentState(L"WALKING");
else if ((wcscmp(player->getCurrentState().c_str(), L"IDLE") != 0) && (wcscmp(player->getCurrentState().c_str(), L"DANCING") != 0))
player->setCurrentState(L"RUNNING");
}
if (input->isKeyDownForFirstTime(Y_KEY)){
player->setCurrentState(DYING);
}
if (input->isKeyDownForFirstTime(I_KEY)){
player->setCurrentState(IDLE);
}
bool viewportMoved = false;
float viewportVx = 0.0f;
float viewportVy = 0.0f;
float vX = pp->getVelocityX();
float vY = pp->getVelocityY();
if (input->isKeyDown(UP_KEY))
{
if (pp->getY() < (viewport->getViewportY() + 0.5f * viewport->getViewportHeight()))
viewportVy -= MAX_PLAYER_VELOCITY;
vY = -1 * MAX_PLAYER_VELOCITY;
vX = 0;
viewportMoved = true;
}
else if (input->isKeyDown(DOWN_KEY))
{
if (pp->getY() > (viewport->getViewportY() + 0.5f * viewport->getViewportHeight()))
viewportVy += MAX_PLAYER_VELOCITY;
vY = MAX_PLAYER_VELOCITY;
vX = 0;
viewportMoved = true;
}
else if (input->isKeyDown(LEFT_KEY))
{
if (pp->getX() < (viewport->getViewportX() + 0.5f * viewport->getViewportWidth()))
viewportVx -= MAX_PLAYER_VELOCITY;
vX = -1 * MAX_PLAYER_VELOCITY;
vY = 0;
viewportMoved = true;
}
else if (input->isKeyDown(RIGHT_KEY))
{
if (pp->getX() > (viewport->getViewportX() + 0.5f * viewport->getViewportWidth()))
viewportVx += MAX_PLAYER_VELOCITY;
vX = MAX_PLAYER_VELOCITY;
vY = 0;
viewportMoved = true;
}
else {
vX = 0.0f;
vY = 0.0f;
}
if (viewportMoved)
viewport->moveViewport((int)floor(viewportVx+0.5f), (int)floor(viewportVy+0.5f), game->getGSM()->getWorld()->getWorldWidth(), game->getGSM()->getWorld()->getWorldHeight());
pp->setVelocity(vX, vY);
}
// 0X43 is HEX FOR THE 'C' VIRTUAL KEY
// THIS CHANGES THE CURSOR IMAGE
if ((input->isKeyDownForFirstTime(C_KEY))
&& input->isKeyDown(VK_SHIFT))
{
Cursor *cursor = game->getGUI()->getCursor();
unsigned int id = cursor->getActiveCursorID();
id++;
//.........这里部分代码省略.........