Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <list>
- float rand(float a, float b)
- {
- return ((float)rand() / (float)RAND_MAX) * (b - a) + a;
- }
- int main()
- {
- sf::VideoMode full = sf::VideoMode::getDesktopMode();
- sf::RenderWindow window(sf::VideoMode(full.height/2, full.height/2), "yes", sf::Style::Titlebar | sf::Style::Close);
- window.setFramerateLimit(120);
- const float RADIUS = full.height / 20.0f;
- sf::CircleShape circle(RADIUS);
- circle.setOutlineThickness(1);
- circle.setOutlineColor(sf::Color::Magenta);
- circle.setFillColor(sf::Color::Green);
- sf::Vector2f speed(rand(3, 6), rand(3, 6));
- const sf::Vector2u wndSize = window.getSize();
- sf::Vector2f currPos;
- std::list<sf::Vector2f> storage;
- while (window.isOpen())
- {
- window.clear();
- sf::Event event;
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- }
- currPos = circle.getPosition();
- storage.push_back(currPos);
- printf("x: %f y: %f\txSpeed: %f ySpeed: %f\n\n", currPos.x, currPos.y, speed.x, speed.y);
- if (currPos.x < 0 || currPos.x + RADIUS * 2 >= wndSize.x)
- speed.x = -speed.x;
- if (currPos.y < 0 || currPos.y + RADIUS * 2 >= wndSize.y)
- speed.y = -speed.y;
- circle.setPosition(currPos.x + speed.x, currPos.y + speed.y);
- if (storage.size() > 100)
- storage.pop_front();
- for (sf::Vector2f meme : storage)
- {
- sf::CircleShape a(RADIUS);
- a.setOutlineThickness(1);
- a.setOutlineColor(sf::Color::Magenta);
- a.setFillColor(sf::Color::Green);
- a.setPosition(meme);
- window.draw(a);
- }
- window.draw(circle);
- window.display();
- }
- return 69;
- }
Add Comment
Please, Sign In to add comment