Compare commits
No commits in common. "46d26b6e61fb210b5d64a2704c43a4bbb620eed1" and "b0aeb3149226f5b977ee2606cbb8671d937b56f5" have entirely different histories.
46d26b6e61
...
b0aeb31492
14 changed files with 2 additions and 355 deletions
|
@ -1,28 +0,0 @@
|
|||
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()
|
|
@ -5,18 +5,14 @@ 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
|
||||
|
||||

|
||||
|
||||
## TODO
|
||||
|
||||
- [ ] Level
|
||||
- [x] Structure
|
||||
- [ ] Structure
|
||||
- [ ] Parsing from XML
|
||||
- [ ] A*
|
||||
- [ ] Entities
|
||||
- [x] Structure
|
||||
- [ ] Strucutre
|
||||
- [ ] Parsing from XML
|
||||
- [ ] Moving
|
||||
- [ ] Decorators (Rules)
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 43 KiB |
|
@ -1,6 +0,0 @@
|
|||
<?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>
|
|
@ -1,12 +0,0 @@
|
|||
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)
|
|
@ -1,41 +0,0 @@
|
|||
//
|
||||
// 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
69
src/Entity.h
|
@ -1,69 +0,0 @@
|
|||
//
|
||||
// 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
44
src/Game.cpp
|
@ -1,44 +0,0 @@
|
|||
#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
44
src/Game.h
|
@ -1,44 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,30 +0,0 @@
|
|||
//
|
||||
// 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
34
src/Level.h
|
@ -1,34 +0,0 @@
|
|||
//
|
||||
// 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
18
src/Utils.h
|
@ -1,18 +0,0 @@
|
|||
//
|
||||
// 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
|
|
@ -1,12 +0,0 @@
|
|||
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)
|
|
@ -1,11 +0,0 @@
|
|||
//
|
||||
// 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();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue