#include "application.h" #include "classicgame/classicgame.h" #include #include const sf::Time TIME_PER_FRAME = sf::seconds(1.f / 60.f); Application::Application() : _game_window({1280, 720}, "Test"), _debug(true), _game(std::make_unique()) { _font.loadFromFile("/usr/share/qtcreator/fonts/SourceCodePro-Regular.ttf"); _grade.setFont(_font); _grade.setPosition(160, 160); _grade.setFillColor(sf::Color(255, 0, 0)); _grade.setCharacterSize(35); _grade.setString("NOT INIT"); } Application::~Application() {} void Application::run() { _game_window.display(); startGameLoop(); } void Application::startGameLoop() { sf::Clock timer; sf::Time time_since_last_update = sf::Time::Zero; while (_game_window.isOpen()) { input(); time_since_last_update += timer.restart(); bool isOneFramePassed = time_since_last_update >= TIME_PER_FRAME; if (isOneFramePassed) { time_since_last_update -= TIME_PER_FRAME; update(); draw(); } } } void Application::input() { sf::Event event; while (_game_window.pollEvent(event)) { _game->input(event); } } void Application::update() { _game->update(); } void Application::draw() { _game_window.clear(); _game->draw(_game_window); _game_window.display(); }