Guest User

Untitled

a guest
Jul 17th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <list>
  3.  
  4. float rand(float a, float b)
  5. {
  6. return ((float)rand() / (float)RAND_MAX) * (b - a) + a;
  7. }
  8.  
  9. int main()
  10. {
  11. sf::VideoMode full = sf::VideoMode::getDesktopMode();
  12.  
  13. sf::RenderWindow window(sf::VideoMode(full.height/2, full.height/2), "yes", sf::Style::Titlebar | sf::Style::Close);
  14.  
  15. window.setFramerateLimit(120);
  16.  
  17. const float RADIUS = full.height / 20.0f;
  18.  
  19. sf::CircleShape circle(RADIUS);
  20. circle.setOutlineThickness(1);
  21. circle.setOutlineColor(sf::Color::Magenta);
  22. circle.setFillColor(sf::Color::Green);
  23.  
  24. sf::Vector2f speed(rand(3, 6), rand(3, 6));
  25.  
  26. const sf::Vector2u wndSize = window.getSize();
  27.  
  28. sf::Vector2f currPos;
  29. std::list<sf::Vector2f> storage;
  30.  
  31. while (window.isOpen())
  32. {
  33. window.clear();
  34.  
  35. sf::Event event;
  36. while (window.pollEvent(event))
  37. {
  38. if (event.type == sf::Event::Closed)
  39. window.close();
  40. }
  41.  
  42. currPos = circle.getPosition();
  43. storage.push_back(currPos);
  44.  
  45. printf("x: %f y: %f\txSpeed: %f ySpeed: %f\n\n", currPos.x, currPos.y, speed.x, speed.y);
  46.  
  47. if (currPos.x < 0 || currPos.x + RADIUS * 2 >= wndSize.x)
  48. speed.x = -speed.x;
  49.  
  50. if (currPos.y < 0 || currPos.y + RADIUS * 2 >= wndSize.y)
  51. speed.y = -speed.y;
  52.  
  53. circle.setPosition(currPos.x + speed.x, currPos.y + speed.y);
  54.  
  55. if (storage.size() > 100)
  56. storage.pop_front();
  57.  
  58. for (sf::Vector2f meme : storage)
  59. {
  60. sf::CircleShape a(RADIUS);
  61. a.setOutlineThickness(1);
  62. a.setOutlineColor(sf::Color::Magenta);
  63. a.setFillColor(sf::Color::Green);
  64.  
  65. a.setPosition(meme);
  66.  
  67. window.draw(a);
  68. }
  69.  
  70.  
  71. window.draw(circle);
  72. window.display();
  73. }
  74.  
  75. return 69;
  76. }
Add Comment
Please, Sign In to add comment