diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/engine.hpp | 36 | ||||
-rw-r--r-- | include/events.hpp | 11 | ||||
-rw-r--r-- | include/world.hpp | 51 |
3 files changed, 84 insertions, 14 deletions
diff --git a/include/engine.hpp b/include/engine.hpp index 0fabdb3..2bde6de 100644 --- a/include/engine.hpp +++ b/include/engine.hpp @@ -5,13 +5,49 @@ #include <events.hpp> +class Engine : public entityx::Receiver<Engine> { +private: + bool gameRunning; + +public: + entityx::SystemManager systems; + + explicit Engine(void); + + void init(void); + void render(entityx::TimeDelta dt); + void update(entityx::TimeDelta dt); + + template<typename T> + inline T* getSystem(void) { + return dynamic_cast<T*>(systems.system<T>().get()); + } + + /*void configure(entityx::EventManager &ev) { + (void)ev; + }*/ + + inline void receive(const GameEndEvent &gee) { + gameRunning = !(gee.really); + } + + inline bool shouldRun(void) const { + return gameRunning; + } +}; + + namespace game { extern entityx::EventManager events; extern entityx::EntityManager entities; + extern Engine engine; + inline void endGame(void) { events.emit<GameEndEvent>(); } } + + #endif // ENGINE_HPP_ diff --git a/include/events.hpp b/include/events.hpp index 1fe7d7a..4d1415c 100644 --- a/include/events.hpp +++ b/include/events.hpp @@ -7,7 +7,9 @@ #include <SDL2/SDL.h> - struct MouseScrollEvent { +#include <string> + +struct MouseScrollEvent { MouseScrollEvent(int sd = 0) : scrollDistance(sd) {} @@ -35,4 +37,11 @@ struct GameEndEvent { bool really; }; +struct BGMToggleEvent { + BGMToggleEvent(std::string f) + : file(f) {} + + std::string file; +} + #endif // EVENTS_HPP_ diff --git a/include/world.hpp b/include/world.hpp index 6b26452..3b116ed 100644 --- a/include/world.hpp +++ b/include/world.hpp @@ -49,7 +49,7 @@ typedef struct { * This pair contains a pointer to the new world, and the new set of * coordinates the player should be at in that world. */ -typedef std::pair<World *, vec2> WorldSwitchInfo; +using WorldSwitchInfo = std::pair<World *, vec2>; /** * Alters how bright world elements are drawn. @@ -130,6 +130,42 @@ public: ~Village(void){} }; + +#include <entityx/entityx.h> + +constexpr const char* WorldWeatherString[3] = { + "None", + "Rainy", + "Snowy" +}; + +class WorldSystem : public entityx::System<WorldSystem>, public entityx::Receiver<WorldSystem> { +private: + WorldWeather weather; + + Mix_Music *bgmObj; + +public: + explicit WorldSystem(void); + + void configure(entityx::EventManager &ev) { + ev.subscribe<BGMToggleEvent>(*this); + } + + void receive(const BGMToggleEvent &bte); + + void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override; + + inline const std::string getWeatherStr(void) const + { return WorldWeatherString[static_cast<int>(weather)]; } + + inline const WorldWeather& getWeatherId(void) const + { return weather; } + + void setWeather(const std::string &s); +}; + + /** * The world class. * This class handles entity creation, management, and deletion. Most @@ -137,23 +173,17 @@ public: * drawing. */ class World { -friend class ItemLight; +//friend class ItemLight; protected: /** * An array of all the world's ground data, populated through * World::generate(). - * * @see generate() */ std::vector<WorldData> worldData; /** - * Contains the current state of weather in the world. - */ - WorldWeather weather; - - /** * Contains the size of the 'worldData' array. */ unsigned int lineCount; @@ -176,11 +206,6 @@ protected: WorldBGType bgType; /** - * SDL_Mixer's object for the loaded BGM. - */ - Mix_Music *bgmObj; - - /** * The filename of the world's BGM file. * * @see setBGM() |