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

76 lines
1.5 KiB
C++

3 years ago
#include "application.h"
#include "classicgame/classicgame.h"
3 years ago
#include <SFML/Graphics/Color.hpp>
#include <SFML/Window/Event.hpp>
3 years ago
const sf::Time TIME_PER_FRAME = sf::seconds(1.f / 60.f);
3 years ago
Application::Application() :
_game_window({1280, 720}, "Test"),
_debug(true),
_game(std::make_unique<ClassicGame>())
3 years ago
{
_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");
3 years ago
}
Application::~Application()
{}
3 years ago
void Application::run()
{
_game_window.display();
_game->run();
exec();
}
void Application::exec()
{
3 years ago
sf::Clock timer;
sf::Time time_since_last_update = sf::Time::Zero;
while (_game_window.isOpen())
{
input();
3 years ago
3 years ago
time_since_last_update += timer.restart();
bool isOneFramePassed = time_since_last_update >= TIME_PER_FRAME;
if (isOneFramePassed)
3 years ago
{
time_since_last_update -= TIME_PER_FRAME;
update();
draw();
}
3 years ago
}
}
void Application::input()
{
sf::Event event;
while (_game_window.pollEvent(event))
3 years ago
{
if (event.type == sf::Event::Closed)
_game_window.close();
_game->input(event);
}
}
void Application::update()
{
_game->update();
3 years ago
}
void Application::draw()
{
_game_window.clear();
_game->draw(_game_window);
_game_window.display();
3 years ago
}