void MovableGameObject::update(const sf::Time& frameTime) { sf::Vector2f position; calculateNextPosition(frameTime, position); setPosition(position); calculateNextVelocity(frameTime, m_velocity); AnimatedGameObject::update(frameTime); }
void MovableGameObject::calculateNextPosition(const sf::Time& frameTime, sf::Vector2f& nextPos) const { sf::Vector2f nextVel; calculateNextVelocity(frameTime, nextVel); sf::Vector2f currentPos = getPosition(); nextPos.x = currentPos.x + nextVel.x * frameTime.asSeconds(); nextPos.y = currentPos.y + nextVel.y * frameTime.asSeconds(); }
void MovableGameObject::calculateNextPosition(const sf::Time& frameTime, sf::Vector2f& nextPos) const { sf::Vector2f position = getPosition(); sf::Vector2f nextVel; calculateNextVelocity(frameTime, nextVel); nextPos.x = position.x + (nextVel.x + m_relativeVelocity.x) * frameTime.asSeconds(); nextPos.y = position.y + (nextVel.y + m_relativeVelocity.y) * frameTime.asSeconds(); }
void MovableGameObject::update(const sf::Time& frameTime) { sf::Vector2f position; calculateNextPosition(frameTime, position); setPosition(position); calculateNextVelocity(frameTime, m_velocity); AnimatedGameObject::update(frameTime); if (m_debugInfo) { m_debugInfo->setString("x: " + std::to_string(getPosition().x) + " y: " + std::to_string(getPosition().y)); m_debugInfo->setPosition(getPosition() + sf::Vector2f(0.f, -30.f)); } }