Entities are now constructable

Added utility function to display error window
Added textures
Added font
Added a way to choose resources location
This commit is contained in:
Teo-CD 2019-06-07 22:20:34 +02:00
parent 46d26b6e61
commit 3666b9e7e9
17 changed files with 155 additions and 39 deletions

View file

@ -7,22 +7,22 @@
#include "Game.h"
Game::Game(const std::vector<std::string>& levels, const std::vector<std::string>& textures)
Game::Game(std::vector<std::string>& levels, std::vector<std::string>& 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(levelFiles.at(levelId).c_str());
pugi::xml_parse_result result = document.load_file((pro_maat::levelFolder+levelFiles.at(levelId)).c_str());
if(!result)
{
std::cerr << "Error while loading level :\n" << "\t" << result.description() << std::endl;
exit(-1);
// std::cerr << "Error while loading level :\n" << "\t" << result.description() << std::endl;
// exit(-1);
pro_maat::errorWindow(result.description());
}
currentLevel = std::make_unique<Level>(document,textures);
@ -34,11 +34,37 @@ void Game::loadTextures()
for(const std::string& filePath : textureFiles)
{
textures.emplace_back(std::make_unique<sf::Texture>());
textures.back()->loadFromFile(filePath);
textures.back()->loadFromFile(pro_maat::textureFolder+filePath);
}
}
void Game::runGame()
{
sf::RenderWindow window(sf::VideoMode(1280,1024),"Project Maat");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
// FIXME : For testing purposes
if (event.type == sf::Event::KeyPressed)
{
currentLevel->runStep();
}
}
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);
}