#include // // Created by trotfunky on 06/06/19. // #include "Game.h" Game::Game(std::vector& levels, std::vector& textures) : levelFiles(std::move(levels)), textureFiles(std::move(textures)) { loadTextures(); } void Game::loadLevel(int levelId) { pugi::xml_document document; pugi::xml_parse_result result = document.load_file((pro_maat::levelFolder+levelFiles.at(levelId)).c_str()); if(!result) { pro_maat::errorWindow(result.description()); } currentLevel = std::make_unique(document,textures); } void Game::loadTextures() { textures.reserve(textureFiles.size()); for(const std::string& filePath : textureFiles) { textures.emplace_back(std::make_unique()); textures.back()->loadFromFile(pro_maat::textureFolder+filePath); } } void Game::runGame() { sf::RenderWindow window(sf::VideoMode(1280,1024),"Project Maat"); sf::Clock clock; while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { window.close(); } } if (clock.getElapsedTime().asMilliseconds() >= 200) { currentLevel->runStep(); clock.restart(); } window.clear(sf::Color::White); // TODO : Consider drawing in a sf::RenderTexture to allow positioning the level at a fixed position ? currentLevel->render(window); window.display(); } } Game::operator bool() const { return (currentLevel ? true : false); }