Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Framework.hpp"
- Framework::Framework()
- {
- pRenderWindow = new sf::RenderWindow(sf::VideoMode(1600, 800, 32), "Billard");
- pRenderWindow->setVerticalSyncEnabled(false);
- pMainEvent = new sf::Event;
- pClock = new sf::Clock;
- mRun = true;
- pBackground = new sf::Texture;
- pBackground->loadFromFile("billardtable.png");
- pSprite = new sf::Sprite;
- pSprite->setTexture(*pBackground);
- pManager = new BallManager();
- Ball *Ball1 = new Ball(std::string("ball1.png"), sf::Vector2f(100, 200), 1, true, 1, 0);
- pManager->insert(Ball1);
- Ball *Ball2 = new Ball(std::string("ball2.png"), sf::Vector2f(1400, 200), 1, true, 1, 180);
- pManager->insert(Ball2);
- }
- Framework::~Framework()
- {
- delete pRenderWindow;
- delete pMainEvent;
- delete pClock;
- pRenderWindow = nullptr;
- pMainEvent = nullptr;
- pClock = nullptr;
- }
- void Framework::run()
- {
- while (mRun == true)
- {
- calculateFrameTime();
- update(mFrameTime);
- handleEvents();
- render();
- quit();
- }
- }
- void Framework::quit()
- {
- if (mRun == false)
- pRenderWindow->close();
- }
- void Framework::update(float frametime)
- {
- pManager->update(frametime);
- }
- void Framework::handleEvents()
- {
- while (pRenderWindow->pollEvent(*pMainEvent))
- {
- if (pMainEvent->type == sf::Event::Closed)
- mRun = false;
- pManager->handle();
- }
- }
- void Framework::render()
- {
- pRenderWindow->clear(sf::Color::Black);
- pRenderWindow->draw(*pSprite);
- pManager->render(pRenderWindow);
- pRenderWindow->display();
- }
- void Framework::calculateFrameTime()
- {
- mFrameTime = pClock->getElapsedTime().asSeconds();
- pClock->restart();
- }
Add Comment
Please, Sign In to add comment