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 Actor::unMove(int axis, float value) { //(2 means both) //move position (0 means X) if (axis == 0 || axis == 2) { setPosx(getPosx() - value); getCollisionBox()->x = getPosx() + getColx(); } //(1 means Y) if (axis == 1 || axis == 2) { setPosy(getPosy() - value); getCollisionBox()->y = getPosy() + getColy(); } }
void Actor::move(float ticks) { //limits acceleration if (getVelx() > VELOCITY) setVelx(VELOCITY); if (getVelx() < -1 * VELOCITY) setVelx(-1 * VELOCITY); if (getVely() > VELOCITY) setVely(VELOCITY); if (getVely() < -1 * VELOCITY) setVely(-1 * VELOCITY); //move position setPosx(getPosx() + getVelx() * ticks / 1000.f); setPosy(getPosy() + getVely() * ticks / 1000.f); //moves collision box to correct position getCollisionBox()->x = getPosx() + getColx(); getCollisionBox()->y = getPosy() + getColy(); }
void Player::move(float ticks) { //limits acceleration to 0 if (getVelx() > VELOCITY) setVelx(VELOCITY); if (getVelx() < -1*VELOCITY) setVelx(-1*VELOCITY); if (getVely() > VELOCITY) setVely(VELOCITY); if (getVely() < -1*VELOCITY) setVely(-1*VELOCITY); //move position setPosx(getPosx() + getVelx() * ticks / 1000.f); setPosy(getPosy() + getVely() * ticks / 1000.f); //move collision box to center of sprite getCollisionBox()->x = getPosx() + getColx(); getCollisionBox()->y = getPosy() + getColy(); //places camera around player setCamera(); }
void BulletManager::animateBullets(sf::Time clock, sf::Time prev_clock) { std::vector<Bullet*> out_of_field; for(auto& bullet : m_bullets) { bullet.second.animate(clock - bullet.first, prev_clock - bullet.first); auto BBox = getCollisionBox(bullet.second); if(BBox.left < -static_cast<int>(videoMode.width)/2 || BBox.top < -static_cast<int>(videoMode.height)/2 || BBox.left > videoMode.width*1.5f || BBox.top > videoMode.height*1.5f) out_of_field.push_back(&bullet.second); } for(auto& bullet : out_of_field) erase(*bullet); }
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; } }
sf::Vector2f Entity::getVisualCentre() { return Physics::getCentre(getCollisionBox()); }