I've been a bit stuck for the past few days. Basically what I want to happen is when pImage(player Sprite) hits a certain height gravity activates and brings the player down. That way when you press the space key you don't continue going up and when released you go down. I Want it similar to that of a mario or traditional platformer. I currently have collision done, it's just this one part that has been driving me mad. I'm a bit new to this so I'm sure there is an easy solution to this problem.
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space))
{
source.y = Up;
pImage.move(0, -moveSpeed* clock.getElapsedTime().asSeconds());
//Debugging: Getting Player Position
std::cout << "Position X: " << pImage.getPosition().x
<< "||Position Y: " << pImage.getPosition().y << std::endl;
}
else if (pImage.getPosition().y >= 341)
{
pImage.move(0, moveSpeed* clock.getElapsedTime().asSeconds());
}