#include #include #include #include "game.h" #include "../config.h" Game::Game(std::shared_ptr window) : window(std::move(window)), gameObjects(), actionController(new ActionController(this)), inputMapper(new InputMapper(this)) { } Game::~Game() { for (auto &gameObject: gameObjects) { delete gameObject; } } void Game::run() { sf::Clock clock; sf::Time TimeSinceLastUpdate = sf::seconds(0); while (window->isOpen()) { inputMapper->processEvents(); TimeSinceLastUpdate += clock.restart(); while (TimeSinceLastUpdate >= FRAME_TIME) { TimeSinceLastUpdate -= FRAME_TIME; update(); inputMapper->processEvents(); } drawFrame(); } } void Game::exit() { window->close(); } void Game::drawFrame() { window->clear(sf::Color::Black); for (auto &gameObject: gameObjects) { gameObject->draw(window.get()); } window->display(); } void Game::addGameObject(GameObject *gameObject) { gameObjects.push_back(gameObject); } void Game::update() { for (auto &gameObject: gameObjects) { gameObject->update(); } }