Class structure, updated UML

Missing : actual code, decorators
This commit is contained in:
trotFunky 2019-06-06 21:30:39 +02:00
parent 2b9593bee8
commit 67435debe6
9 changed files with 113 additions and 10 deletions

View file

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.14) cmake_minimum_required(VERSION 3.14)
project(src) project(project_maat)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH}) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})

View file

@ -12,11 +12,11 @@ This game is aimed to be a puzzle game in which the player sets different laws f
## TODO ## TODO
- [ ] Level - [ ] Level
- [ ] Structure - [x] Structure
- [ ] Parsing from XML - [ ] Parsing from XML
- [ ] A* - [ ] A*
- [ ] Entities - [ ] Entities
- [ ] Strucutre - [x] Structure
- [ ] Parsing from XML - [ ] Parsing from XML
- [ ] Moving - [ ] Moving
- [ ] Decorators (Rules) - [ ] Decorators (Rules)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View file

@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.14) cmake_minimum_required(VERSION 3.14)
project(src) project(project_maat)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH}) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
add_library(engine Level.cpp Level.h Entity.cpp Entity.h) add_library(engine Level.cpp Level.h Entity.cpp Entity.h Game.cpp Game.h)
target_link_libraries(engine target_link_libraries(engine
sfml-window sfml-window

View file

@ -5,9 +5,55 @@
#ifndef SRC_ENTITY_H #ifndef SRC_ENTITY_H
#define SRC_ENTITY_H #define SRC_ENTITY_H
#include <SFML/Graphics.hpp>
class Entity {
enum class EntityType
{
Citizen,
Player,
House,
Car,
};
enum class State
{
Moving,
Fleeing,
Waiting,
Idle,
};
enum class Orientation
{
Nort,
East,
South,
West,
};
class Entity
{
public:
Entity();
void render(sf::RenderWindow& renderWindow) const;
void move();
void update();
/// Position of the target of the current action on the map
sf::Vector2i target;
private:
// 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;
}; };

6
src/Game.cpp Normal file
View file

@ -0,0 +1,6 @@
//
// Created by trotfunky on 06/06/19.
//
#include "Game.h"

38
src/Game.h Normal file
View file

@ -0,0 +1,38 @@
//
// Created by trotfunky on 06/06/19.
//
#ifndef SRC_GAME_H
#define SRC_GAME_H
#include <SFML/Graphics.hpp>
#include <vector>
#include "Level.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
void loadLevel(int levelId);
Level currentLevel;
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

View file

@ -5,13 +5,26 @@
#ifndef SRC_LEVEL_H #ifndef SRC_LEVEL_H
#define SRC_LEVEL_H #define SRC_LEVEL_H
#include <SFML/Graphics.hpp>
#include <vector>
#include "Entity.h"
#include "Game.h"
class Level { class Level {
Level(); public:
Level(const TextureStore& textureStore);
void render(sf::RenderWindow& renderWindow) const;
void runStep() const;
private: private:
int width; const sf::Vector2i size;
int height;
std::vector<Entity> entities;
const TextureStore& textures;
}; };

View file

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.14) cmake_minimum_required(VERSION 3.14)
project(src) project(project_maat)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH}) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})