Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
670 B
0
Indexable
Never
#include <SFML/Graphics.hpp>

int main() {
    sf::RenderWindow window(sf::VideoMode(800, 600), "Simple Animation");

    sf::CircleShape ball(50);
    ball.setFillColor(sf::Color::Red);

    float dx = 2.0f;
    float dy = -2.0f;

    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        ball.move(dx, dy);

        if (ball.getPosition().y > 550 || ball.getPosition().y < 0)
            dy = -dy;

        window.clear();
        window.draw(ball);
        window.display();
    }

    return 0;
}