Compare commits

..

3 commits

Author SHA1 Message Date
46d26b6e61 Started object construction and parsing
Simplified some structures
Missing : Entity construction
2019-06-07 02:59:27 +02:00
67435debe6 Class structure, updated UML
Missing : actual code, decorators
2019-06-06 21:30:39 +02:00
2b9593bee8 Project structure and UML first draft 2019-06-06 17:07:24 +02:00
14 changed files with 355 additions and 2 deletions

28
CMakeLists.txt Normal file
View file

@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.14)
project(project_maat)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
add_subdirectory(src)
add_subdirectory(tests)
# Detect and add SFML
find_package(SFML COMPONENTS system window graphics network audio REQUIRED)
if(NOT SFML_FOUND)
message(FATAL_ERROR "SFML could not be found")
endif()
# Detect and add GTest
find_package(GTest REQUIRED)
if(GTest_FOUND)
enable_testing()
else()
message(FATAL_ERROR "GTest could not be found")
endif()
# Find PugiXML
find_path(PugiXML_INCLUDE_DIR pugixml.hpp)
if(NOT IS_DIRECTORY ${PugiXML_INCLUDE_DIR})
message(FATAL_ERROR "PugiXML could not be found")
endif()

View file

@ -5,14 +5,18 @@ Project Maat is the codename of my C++ course "mini-project" based on the quote
This game is aimed to be a puzzle game in which the player sets different laws for the world and the people within it as to control what happens after hitting "play" and achieve the level's goal. I was inspired both by [The Incredible Machine](https://en.wikipedia.org/wiki/The_Incredible_Machine_(video_game)) and its successors and by a much more recent game : [Baba is you](https://en.wikipedia.org/wiki/Baba_Is_You).
## Structure
![UML Diagram](UML_Class_Diagram.png)
## TODO
- [ ] Level
- [ ] Structure
- [x] Structure
- [ ] Parsing from XML
- [ ] A*
- [ ] Entities
- [ ] Strucutre
- [x] Structure
- [ ] Parsing from XML
- [ ] Moving
- [ ] Decorators (Rules)

BIN
UML_Class_Diagram.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

6
resources/test_level.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version = "1.0"?>
<Level w="10" h="10" textureId="0">
<Entity x="0" y="0" type="Citizen"/>
<Entity x="0" y="1" type="Citizen"/>
<Entity x="1" y="1" type="House"/>
</Level>

12
src/CMakeLists.txt Normal file
View file

@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.14)
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 Utils.h Utils.h)
target_link_libraries(engine
sfml-window
sfml-graphics
sfml-system)

41
src/Entity.cpp Normal file
View file

@ -0,0 +1,41 @@
//
// Created by trotfunky on 06/06/19.
//
#include "Entity.h"
const std::map<std::string,EntityType> 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);
}

69
src/Entity.h Normal file
View file

@ -0,0 +1,69 @@
//
// Created by trotfunky on 06/06/19.
//
#ifndef SRC_ENTITY_H
#define SRC_ENTITY_H
#include <SFML/Graphics.hpp>
#include <pugixml.hpp>
#include "Utils.h"
enum class EntityType
{
Citizen,
Player,
House,
Car,
};
enum class State
{
Moving,
Fleeing,
Waiting,
Idle,
};
enum class Orientation
{
Nort,
East,
South,
West,
};
class Entity
{
public:
/// 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<std::string,EntityType> entityTypeLookup;
// As it contains position, size and orientation, we do not need anything more
sf::RectangleShape shape;
State currentState;
/// Used with rules : last to update has priority
State nextState;
/// Used with rules : last to update has priority
sf::Vector2i nextTarget;
};
#endif //SRC_ENTITY_H

44
src/Game.cpp Normal file
View file

@ -0,0 +1,44 @@
#include <memory>
//
// Created by trotfunky on 06/06/19.
//
#include "Game.h"
Game::Game(const std::vector<std::string>& levels, const std::vector<std::string>& 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<Level>(document,textures);
}
void Game::loadTextures()
{
textures.reserve(textureFiles.size());
for(const std::string& filePath : textureFiles)
{
textures.emplace_back(std::make_unique<sf::Texture>());
textures.back()->loadFromFile(filePath);
}
}
void Game::runGame()
{
}

44
src/Game.h Normal file
View file

@ -0,0 +1,44 @@
//
// Created by trotfunky on 06/06/19.
//
#ifndef SRC_GAME_H
#define SRC_GAME_H
#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>
#include "Level.h"
#include "Entity.h"
// Used for convenience
using TextureStore = std::vector<std::unique_ptr<sf::Texture>>;
class Game {
public:
Game(const std::vector<std::string>& levels, const std::vector<std::string>& 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);
std::unique_ptr<Level> currentLevel;
// This should not be called before a level has been loaded
void runGame();
private:
/// Store the paths to level files
const std::vector<std::string> levelFiles;
/// Store the paths to texture files
const std::vector<std::string> textureFiles;
/// Stores pointers to textures for future use
TextureStore textures;
void loadTextures();
};
#endif //SRC_GAME_H

30
src/Level.cpp Normal file
View file

@ -0,0 +1,30 @@
//
// Created by trotfunky on 06/06/19.
//
#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
{
}

34
src/Level.h Normal file
View file

@ -0,0 +1,34 @@
//
// Created by trotfunky on 06/06/19.
//
#ifndef SRC_LEVEL_H
#define SRC_LEVEL_H
#include <SFML/Graphics.hpp>
#include <pugixml.hpp>
#include <vector>
#include <cstring>
#include "Utils.h"
#include "Entity.h"
using TextureStore = std::vector<std::unique_ptr<sf::Texture>>;
class Level {
public:
Level(const pugi::xml_document& xmlDoc, const TextureStore& textureStore);
void render(sf::RenderWindow& renderWindow) const;
void runStep() const;
private:
const sf::Vector2i size;
std::vector<Entity> entities;
const TextureStore& textures;
};
#endif //SRC_LEVEL_H

18
src/Utils.h Normal file
View file

@ -0,0 +1,18 @@
//
// Created by trotfunky on 07/06/19.
//
#ifndef PROJECT_MAAT_UTILS_H
#define PROJECT_MAAT_UTILS_H
#include <cstdint>
namespace pro_maat
{
static constexpr uint8_t pixelsPerUnit = 20;
}
#endif //PROJECT_MAAT_UTILS_H

12
tests/CMakeLists.txt Normal file
View file

@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.14)
project(project_maat)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
add_executable(gTests gTests.cpp gTests.cpp)
target_link_libraries(gTests
engine
gtest
pthread)

11
tests/gTests.cpp Normal file
View file

@ -0,0 +1,11 @@
//
// Created by Teo-CD on 06/06/19.
//
#include <gtest/gtest.h>
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS();
}