Guest User

Framework.cpp

a guest
Mar 23rd, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include "Framework.hpp"
  2.  
  3. Framework::Framework()
  4. {
  5. pRenderWindow = new sf::RenderWindow(sf::VideoMode(1600, 800, 32), "Billard");
  6. pRenderWindow->setVerticalSyncEnabled(false);
  7. pMainEvent = new sf::Event;
  8. pClock = new sf::Clock;
  9. mRun = true;
  10.  
  11. pBackground = new sf::Texture;
  12. pBackground->loadFromFile("billardtable.png");
  13.  
  14. pSprite = new sf::Sprite;
  15. pSprite->setTexture(*pBackground);
  16.  
  17. pManager = new BallManager();
  18.  
  19. Ball *Ball1 = new Ball(std::string("ball1.png"), sf::Vector2f(100, 200), 1, true, 1, 0);
  20.  
  21. pManager->insert(Ball1);
  22.  
  23. Ball *Ball2 = new Ball(std::string("ball2.png"), sf::Vector2f(1400, 200), 1, true, 1, 180);
  24.  
  25. pManager->insert(Ball2);
  26. }
  27.  
  28. Framework::~Framework()
  29. {
  30. delete pRenderWindow;
  31. delete pMainEvent;
  32. delete pClock;
  33.  
  34. pRenderWindow = nullptr;
  35. pMainEvent = nullptr;
  36. pClock = nullptr;
  37.  
  38. }
  39.  
  40. void Framework::run()
  41. {
  42. while (mRun == true)
  43. {
  44. calculateFrameTime();
  45.  
  46. update(mFrameTime);
  47. handleEvents();
  48. render();
  49.  
  50. quit();
  51. }
  52. }
  53.  
  54. void Framework::quit()
  55. {
  56. if (mRun == false)
  57. pRenderWindow->close();
  58. }
  59.  
  60. void Framework::update(float frametime)
  61. {
  62. pManager->update(frametime);
  63. }
  64.  
  65. void Framework::handleEvents()
  66. {
  67. while (pRenderWindow->pollEvent(*pMainEvent))
  68. {
  69. if (pMainEvent->type == sf::Event::Closed)
  70. mRun = false;
  71.  
  72. pManager->handle();
  73. }
  74. }
  75.  
  76. void Framework::render()
  77. {
  78. pRenderWindow->clear(sf::Color::Black);
  79. pRenderWindow->draw(*pSprite);
  80.  
  81. pManager->render(pRenderWindow);
  82.  
  83. pRenderWindow->display();
  84. }
  85.  
  86.  
  87. void Framework::calculateFrameTime()
  88. {
  89. mFrameTime = pClock->getElapsedTime().asSeconds();
  90. pClock->restart();
  91. }
Add Comment
Please, Sign In to add comment