diff --git a/UML_Class_Diagram.png b/UML_Class_Diagram.png index bb6dacb..5f40a3d 100644 Binary files a/UML_Class_Diagram.png and b/UML_Class_Diagram.png differ diff --git a/resources/test_level.xml b/resources/test_level.xml new file mode 100644 index 0000000..7b4af30 --- /dev/null +++ b/resources/test_level.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 671a0a5..df21f86 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,7 +4,7 @@ project(project_maat) set(CMAKE_CXX_STANDARD 17) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH}) -add_library(engine Level.cpp Level.h Entity.cpp Entity.h Game.cpp Game.h) +add_library(engine Level.cpp Level.h Entity.cpp Entity.h Game.cpp Game.h Utils.h Utils.h) target_link_libraries(engine sfml-window diff --git a/src/Entity.cpp b/src/Entity.cpp index 2f48d00..fd4cfca 100644 --- a/src/Entity.cpp +++ b/src/Entity.cpp @@ -3,3 +3,39 @@ // #include "Entity.h" + +const std::map Entity::entityTypeLookup = { + {"Citizen",EntityType::Citizen}, + {"Player",EntityType::Player}, + {"House",EntityType::House}, + {"Car",EntityType::Car}}; + +Entity::Entity(int x, int y, EntityType type, int width, int height) +{ + +} + +Entity::Entity(const pugi::xml_node& entityNode) +{ + +} + +void Entity::render(sf::RenderWindow& renderWindow) const +{ + +} + +void Entity::move() +{ + +} + +void Entity::update() +{ + +} + +const sf::RectangleShape& Entity::getShape() const +{ + return(shape); +} diff --git a/src/Entity.h b/src/Entity.h index b79c1b3..be52d46 100644 --- a/src/Entity.h +++ b/src/Entity.h @@ -6,6 +6,9 @@ #define SRC_ENTITY_H #include +#include + +#include "Utils.h" enum class EntityType @@ -36,15 +39,21 @@ enum class Orientation class Entity { public: - Entity(); + /// x,y, width and height are in grid coordinates + Entity(int x, int y, EntityType type, int width = 1, int height = 1); + Entity(const pugi::xml_node& entityNode); void render(sf::RenderWindow& renderWindow) const; void move(); void update(); + const sf::RectangleShape& getShape() const; + /// Position of the target of the current action on the map sf::Vector2i target; private: + static const std::map entityTypeLookup; + // As it contains position, size and orientation, we do not need anything more sf::RectangleShape shape; diff --git a/src/Game.cpp b/src/Game.cpp index 8428f60..6983d39 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -1,6 +1,44 @@ +#include + // // Created by trotfunky on 06/06/19. // #include "Game.h" + +Game::Game(const std::vector& levels, const std::vector& textures) +{ + + + loadTextures(); +} + +void Game::loadLevel(int levelId) +{ + pugi::xml_document document; + pugi::xml_parse_result result = document.load_file(levelFiles.at(levelId).c_str()); + + if(!result) + { + std::cerr << "Error while loading level :\n" << "\t" << result.description() << std::endl; + exit(-1); + } + + 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(filePath); + } +} + +void Game::runGame() +{ + +} diff --git a/src/Game.h b/src/Game.h index 7dbc0f6..da9f7b2 100644 --- a/src/Game.h +++ b/src/Game.h @@ -7,8 +7,10 @@ #include #include +#include #include "Level.h" +#include "Entity.h" // Used for convenience @@ -19,9 +21,13 @@ public: Game(const std::vector& levels, const std::vector& textures); /// Loads the level of corresponding ID from Game::levelFiles + /// Closes the program if there is a fatal error (Missing file, bad file...) void loadLevel(int levelId); - Level currentLevel; + std::unique_ptr currentLevel; + + // This should not be called before a level has been loaded + void runGame(); private: /// Store the paths to level files diff --git a/src/Level.cpp b/src/Level.cpp index a6a22d8..1c0903b 100644 --- a/src/Level.cpp +++ b/src/Level.cpp @@ -3,3 +3,28 @@ // #include "Level.h" + + +Level::Level(const pugi::xml_document& xmlDoc, const TextureStore& textureStore) + : textures(textureStore), + size(xmlDoc.child("Level").attribute("width").as_int(),xmlDoc.child("Level").attribute("width").as_int()) +{ + pugi::xml_node levelNode = xmlDoc.child("Level"); + for(const pugi::xml_node& child : levelNode.children()) + { + if(!strncmp(child.name(),"Entity",6)) + { + entities.emplace_back(child); + } + } +} + +void Level::render(sf::RenderWindow& renderWindow) const +{ + +} + +void Level::runStep() const +{ + +} diff --git a/src/Level.h b/src/Level.h index a2a03be..63379f9 100644 --- a/src/Level.h +++ b/src/Level.h @@ -6,15 +6,18 @@ #define SRC_LEVEL_H #include +#include #include +#include +#include "Utils.h" #include "Entity.h" -#include "Game.h" +using TextureStore = std::vector>; class Level { public: - Level(const TextureStore& textureStore); + Level(const pugi::xml_document& xmlDoc, const TextureStore& textureStore); void render(sf::RenderWindow& renderWindow) const; void runStep() const; diff --git a/src/Utils.h b/src/Utils.h new file mode 100644 index 0000000..8fa40a5 --- /dev/null +++ b/src/Utils.h @@ -0,0 +1,18 @@ +// +// Created by trotfunky on 07/06/19. +// + +#ifndef PROJECT_MAAT_UTILS_H +#define PROJECT_MAAT_UTILS_H + +#include + + +namespace pro_maat +{ + +static constexpr uint8_t pixelsPerUnit = 20; + +} + +#endif //PROJECT_MAAT_UTILS_H