#include #include using namespace std; int main() { bool Jump=true; const float gravitation = 5; int GroundHeight = 499 , JumpSpeed = 30; sf::Vector2f Vel (sf::Vector2f (0,0)); sf::RectangleShape rect1(sf::Vector2f(120, 50)); rect1.setFillColor(sf::Color::Blue); rect1.setSize(sf::Vector2f(20, 20)); rect1.setPosition(0,50); sf::RenderWindow window(sf::VideoMode(500, 500), "SFML works!"); window.setFramerateLimit(60); while (window.isOpen()) { Vel.x = 0; if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)&&rect1.getPosition().y + rect1.getSize().y == GroundHeight){ Vel.y = -JumpSpeed; rect1.move(Vel.x,Vel.y); }else if(rect1.getPosition().y + rect1.getSize().y < GroundHeight){ Vel.y += gravitation; rect1.move(0,Vel.y); }else{ rect1.setPosition(rect1.getPosition().x , GroundHeight - rect1.getSize().x); } sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } window.clear(sf::Color::Black); window.draw(rect1); window.display(); } return 0; }