void Sprite::drawTexture() { GLfloat x = getBoxX(); if( x < 0 ) { x = 0; } //GameRender::drawFullTexture(textureBox, Vector2f(x, getBoxY()), getBoxWidth(), getBoxHeight()); int currentState = getCurrentState(); if ( currentState == GameCoreStates::DOUBLE_JUMP ) { currentState = GameCoreStates::JUMPING; } if ( getCurrentState() == GameCoreStates::FAST_ATTACK ) { int attackState = getPreviousState(); /*GameRender::drawFullTexture(textureBox, Vector2f(weaponCollisionBoxes.at(attackState).getX(), weaponCollisionBoxes.at(attackState).getY()), weaponCollisionBoxes.at(attackState).getWidth(), weaponCollisionBoxes.at(attackState).getHeight());*/ currentState = ( GameCoreStates::FAST_ATTACK - 1 ) + getPreviousState(); } if ( getCurrentState() == GameCoreStates::FALLING ) { currentState = 8; } GameRender::drawSpriteTexture(texture, position, handlerAnimation->getCurrentFrame(), width, height, handlerAnimation->getAnimationDirection(), currentState ); }
void BeforeLevelState::resume(RoidsApp * application) { ApplicationState * s = getPreviousState(); changeState(application, this); setPreviousState(s); _screen->setMessage(getMessage()); _application->addScreen(_screen); }
bool QuitConfirmState::onKeyPressed(unsigned char key) { if(key == 'y') { cg::Manager::instance()->shutdownApp(); return true; } else if(key =='n') { getPreviousState()->resume(_application); return true; } return false; }
void CloudsTransitionController::transitionToInterlude(float inDuration,float outDuration){ confirmEmpty("transitionToInterlude"); //we are in a visual system if(getPreviousState() == TRANSITION_VISUALSYSTEM_IN){ cout<<"VISUAL SYSTEM --> INTERLUDE MAP"<<endl; currentState = TRANSITION_VISUALSYSTEM_IN; queueState(TRANSITION_VISUALSYSTEM_OUT, outDuration); queueState(TRANSITION_INTERLUDE_IN, inDuration); } //we are in an interview else if(getPreviousState() == TRANSITION_INTERVIEW_IN){ cout<<"INTERVIEW --> INTERLUDE MAP"<<endl; queueState(TRANSITION_INTERVIEW_OUT, outDuration); queueState(TRANSITION_INTERLUDE_IN, inDuration); } startTransition(); }
bool Sprite::isPlayerOnTheAir() { if ( getCurrentState() != GameCoreStates::JUMPING && getCurrentState() != GameCoreStates::DOUBLE_JUMP && getCurrentState() != GameCoreStates::FALLING && !(getPreviousState() == GameCoreStates::JUMPING && getCurrentState() == GameCoreStates::FAST_ATTACK) ) { return false; } return true; }
void Sprite::movePosYWithSpeed() { characterMovement.playerMoveInY = false || characterMovement.playerMoveInY; characterMovement.playerMoveInYInCurrentFrame = false; countY++; if ( countY > delayMovementSprite.at(getCurrentState()).y ) { countY = 0; if( getBoxY() + getBoxHeight() <= 880.0f ) { handlerAnimation->changeDirectionY( getSpeedY() ); if ( !getPlayerDirectionYBasedInDirection() ) { return; } rigidBody->applyNaturalPhysicForces(GamePhysics::Y, &speed.x, &speed.y, getCurrentState(), handlerAnimation->getAnimationDirection(), getPreviousState()); characterMovement.playerMoveInY = true; characterMovement.playerMoveInYInCurrentFrame = true; collisionHandler->checkTileCollisionY(*getCollisionBox(), &speed.y, handlerAnimation->getDirectionY(), directionsMove); spriteCollisionBox->setBoxYBasedOnSpeed(spriteCollisionBox->getY() + getSpeedY()); position.y = spriteCollisionBox->getY() - spriteCollisionBox->getOffset().y; isOnGround = collisionHandler->onTheGround(*getCollisionBox()); collisionHandler->checkStateCollisionPlayer(*this); for(std::string::size_type i = 0; i < weaponCollisionBoxes.size(); i++) { weaponCollisionBoxes.at(i).setY( position.y ); } return; } speed.y = 0.0f; characterMovement.playerMoveInX = false; characterMovement.playerMoveInY = false; } }
void Sprite::setSpeedY(GLfloat speedY) { if ( getCurrentState() == GameCoreStates::FAST_ATTACK ) { if ( getPreviousState() == GameCoreStates::JUMPING ) { speedY = -4.0f; rigidBody->getMaxSpeed().at(getCurrentState()).y = speedY; } else { speedY = 0.0f; rigidBody->getMaxSpeed().at(getCurrentState()).y = speedY; } } speed.y = speedY; }
void PausedState::pause() { getPreviousState()->resume(_application); }
void Sprite::movePosXWithSpeed() { characterMovement.playerMoveInX = false || characterMovement.playerMoveInX; characterMovement.playerMoveInXInCurrentFrame = false; countX++; if ( countX > delayMovementSprite.at(getCurrentState()).x ) { countX = 0; handlerAnimation->changeDirectionY( getSpeedY() ); if ( Camera::getInstance()->isCameraLimit( getSpeedX()) ) { characterMovement.playerMoveInX = false; characterMovement.playerMoveInXInCurrentFrame = false; setSpeedX(0.0f); int animationDirection = getHandlerAnimation()->getAnimationDirection(); GLfloat correctPosition = 0.0f; switch( animationDirection ) { case SpriteData::RIGHT: { correctPosition = Collider::getInstance()->getLevelLength() - spriteCollisionBox->getWidth(); position.x = correctPosition - spriteCollisionBox->getOffset().x; break; } case SpriteData::LEFT: { correctPosition = -spriteCollisionBox->getX(); setNormalPositionX( correctPosition ); break; } } getCollisionBox()->setX( getPosX() + getCollisionBox()->getOffsetXBasedOnDirection(animationDirection), animationDirection ); return; } bool canMove = collisionHandler->checkPositionWithinLevelLength(*spriteCollisionBox, directionsMove, speed, handlerAnimation->getAnimationDirection()); if ( handlerAnimation->getAnimationDirection() == SpriteData::RIGHT ) { if ( canMove ) { if ( !directionsMove.canMoveXRight || getSpeedX() == 0.0f) { return; } characterMovement.playerMoveInX = true; characterMovement.playerMoveInXInCurrentFrame = true; rigidBody->applyNaturalPhysicForces(GamePhysics::X, &speed.x, &speed.y, getCurrentState(), handlerAnimation->getAnimationDirection(), getPreviousState()); collisionHandler->checkTileCollisionX(*getCollisionBox(), &speed.x, handlerAnimation->getAnimationDirection(), directionsMove); collisionHandler->checkStateCollisionXAxis(*this); isOnGround = collisionHandler->onTheGround(*getCollisionBox()); for(std::string::size_type i = 0; i < weaponCollisionBoxes.size(); i++) { weaponCollisionBoxes.at(i).setX( position.x, handlerAnimation->getAnimationDirection() ); } return; } } else if ( canMove ) { if ( !directionsMove.canMoveXLeft || getSpeedX() == 0.0f ) { return; } rigidBody->applyNaturalPhysicForces(GamePhysics::X, &speed.x, &speed.y, getCurrentState(), handlerAnimation->getAnimationDirection(), getPreviousState()); characterMovement.playerMoveInX = true; characterMovement.playerMoveInXInCurrentFrame = true; collisionHandler->checkTileCollisionX(*getCollisionBox(), &speed.x, handlerAnimation->getAnimationDirection(), directionsMove); collisionHandler->checkStateCollisionXAxis(*this); isOnGround = collisionHandler->onTheGround(*getCollisionBox()); for(std::string::size_type i = 0; i < weaponCollisionBoxes.size(); i++) { weaponCollisionBoxes.at(i).setX( position.x + (width - weaponCollisionBoxes.at(i).getOffset().x) - weaponCollisionBoxes.at(i).getWidth(), handlerAnimation->getAnimationDirection() ); } return; } characterMovement.playerMoveInX = false; speed.x = 0.0f; } }