You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
project-kyoku/src/application.cpp

72 lines
1.4 KiB
C++

#include "application.h"
#include "classicgame/classicgame.h"
#include <SFML/Graphics/Color.hpp>
#include <SFML/Window/Event.hpp>
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<ClassicGame>())
{
_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();
}