Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include "program.h"
  2. #include "ball.h"
  3.  
  4. Program::Program(int width, int height) : w(width), h(height), window(sf::VideoMode(width, height), "SFML Test"), ball(w/2, h/2)
  5. {
  6.  
  7. }
  8.  
  9. int Program::mainLoop()
  10. {
  11. sf::Event events;
  12. sf::Clock clock;
  13.  
  14. if (!window.isOpen())
  15. {
  16. return EXIT_FAILURE;
  17. }
  18.  
  19. while (window.isOpen())
  20. {
  21. while (window.pollEvent(events))
  22. {
  23. if (events.type == sf::Event::EventType::Closed)
  24. {
  25. window.close();
  26. }
  27.  
  28. eventHandler(events);
  29. }
  30.  
  31. if (clock.getElapsedTime().asSeconds() >= 1.0 / 60.0)
  32. {
  33. ball.update();
  34. clock.restart();
  35. }
  36.  
  37. //clear
  38. window.clear(sf::Color::Black);
  39.  
  40. //Features
  41. //sf::RectangleShape rectWin(sf::Vector2f(700, 700));
  42. //rectWin.setPosition((w - 700)/2, (h-700)/2);
  43.  
  44. //Draw
  45. //window.draw(rectWin);
  46. ball.draw(window);
  47.  
  48.  
  49.  
  50. //Display
  51. window.display();
  52. }
  53. }
  54.  
  55. void Program::eventHandler(sf::Event events)
  56. {
  57. if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A))
  58. {
  59. ball.setRotSpeed(-0.1);
  60. }
  61. if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D))
  62. {
  63. ball.setRotSpeed(0.1);
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement