]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
no more getSystem
authorClyne Sullivan <tullivan99@gmail.com>
Sat, 29 Apr 2017 22:28:28 +0000 (18:28 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Sat, 29 Apr 2017 22:28:28 +0000 (18:28 -0400)
27 files changed:
assets/player/player.png
assets/player/player_b.png [new file with mode: 0644]
assets/player/player_w.png [deleted file]
config/controls.dat
include/components.hpp
include/inventory.hpp
include/particle.hpp
include/player.hpp
include/quest.hpp
include/weather.hpp
include/window.hpp
include/world.hpp
main.cpp
src/attack.cpp
src/components.cpp
src/engine.cpp
src/inventory.cpp
src/particle.cpp
src/player.cpp
src/quest.cpp
src/render.cpp
src/ui.cpp
src/ui_menu.cpp
src/weather.cpp [new file with mode: 0644]
src/window.cpp
src/world.cpp
xml/entities.xml

index 7a2312790ee23e50c6eb654903316d1392ca85b9..6a3fff8ad1fe1adc7d5f411103450c1ba1b381ef 100644 (file)
Binary files a/assets/player/player.png and b/assets/player/player.png differ
diff --git a/assets/player/player_b.png b/assets/player/player_b.png
new file mode 100644 (file)
index 0000000..7a23127
Binary files /dev/null and b/assets/player/player_b.png differ
diff --git a/assets/player/player_w.png b/assets/player/player_w.png
deleted file mode 100644 (file)
index 6a3fff8..0000000
Binary files a/assets/player/player_w.png and /dev/null differ
index c0414cdfb71d446b0bb8521a5144dfe261c7b842..679c014997ea62f66b389359dde88a31cf906777 100644 (file)
@@ -1,6 +1,6 @@
 119
 97
 100
-1073742048
 1073742049
+1073742048
 101
index 87d4293fbb1ef3ae09714644094a637ab5b08291..fe8e7a60f6f49d2a64bed521e2c27f913bb36068 100644 (file)
@@ -655,14 +655,15 @@ public:
 
 class RenderSystem : public entityx::System<RenderSystem> {
 private:
-       std::string loadTexString;
-       Texture loadTexResult;
+       static std::string loadTexString;
+       static Texture loadTexResult;
 
 public:
-       Texture loadTexture(const std::string& file);
+       static Texture loadTexture(const std::string& file);
+       static void render(void);
+
        void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override
        { (void)en; (void)ev; (void)dt; }
-       void render(void);
 };
 
 class DialogSystem : public entityx::System<DialogSystem>, public entityx::Receiver<DialogSystem> {
index adf16f1eb3f6dc58af6859b68b7a65a872a30b3d..8329d72ac79baa38409e8cae8f45e0ad18eea644 100644 (file)
@@ -99,41 +99,35 @@ private:
        constexpr static float inventoryZ = -5.0f;
        constexpr static unsigned int rowSize = 8;
 
-       /**
-        * A 'database' of all existing items.
-        */
-       std::unordered_map<std::string, Item> itemList;
+       static std::unordered_map<std::string, Item> itemList;
+       static std::vector<InventoryEntry> items;
 
-       /**
-        * A vector for the player's inventory slots.
-        */
-    std::vector<InventoryEntry> items;
+       static vec2 hotStart;
+       static vec2 hotEnd;
+       static vec2 fullStart;
+       static vec2 fullEnd;
 
+       static int movingItem;
+       static bool fullInventory;
 
-       vec2 hotStart, hotEnd;
-       vec2 fullStart, fullEnd;
-
-       int movingItem = -1;
-       bool fullInventory = false;
-
-       void loadItems(void);
+       static void loadItems(void);
 public:
-    InventorySystem(int size = 20);
+       InventorySystem(int size = 20);
 
-    void configure(entityx::EventManager &ev);
-    void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
-    void receive(const KeyDownEvent &kde);
+       void configure(entityx::EventManager &ev);
+       void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
+       void receive(const KeyDownEvent &kde);
        void receive(const MouseClickEvent &mce);
        void receive(const MouseReleaseEvent &mce);
 
-       void render(void);
+       static void render(void);
 
        /**
         * Adds 'count' 'name's to the inventory.
         * @param name the name of the item
         * @param count the quantity of the item to give
         */
-       void add(const std::string& name, int count);
+       static void add(const std::string& name, int count);
 
        /**
         * Takes 'count' 'name's from the inventory.
@@ -143,11 +137,10 @@ public:
         * @param count the quantity of the item to take
         * @return true if the operation could be completed
         */
-       bool take(const std::string& name, int count);
+       static bool take(const std::string& name, int count);
 
-       inline Item getItem(const std::string& s) {
-               return itemList[s];
-       }
+       static inline Item getItem(const std::string& s)
+       { return itemList[s]; }
 };
 
 #endif // INVENTORY_HPP_
index 822ac41a47deaaaa9bdcaaa6a7cac3e446299caf..31825fc2f9101391e854d11d4f42744ea7cc7635 100644 (file)
@@ -29,21 +29,21 @@ struct Particle {
 
 class ParticleSystem : public entityx::System<ParticleSystem> {
 private:
-       std::vector<Particle> parts;
-       unsigned int maximum;
+       static std::vector<Particle> parts;
+       static unsigned int maximum;
 
 public:
        ParticleSystem(unsigned int max = 2048);
 
-       void add(const vec2& pos, const ParticleType& type, const int& timeleft = 3000,
+       static void add(const vec2& pos, const ParticleType& type, const int& timeleft = 3000,
                const unsigned char& color = 0);
-       void addMultiple(const int& count, const ParticleType& type, std::function<vec2(void)> f,
+       static void addMultiple(const int& count, const ParticleType& type, std::function<vec2(void)> f,
                const int& timeleft = 3000, const unsigned char& color = 0);
 
-       void render(void);
+       static void render(void);
        void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
 
-       int getCount(void) const;
+       static int getCount(void);
 };
 
 #endif // PARTICLE_HPP_
index efac984995a9ee0bd10a568241a337c55223a47d..17ce2c1856ca552abd18c9c1f1649001ccb8f45e 100644 (file)
@@ -23,22 +23,21 @@ constexpr const float PLAYER_SPEED_CONSTANT = 0.03f;
  */
 class PlayerSystem : public entityx::System<PlayerSystem>, public entityx::Receiver<PlayerSystem> {
 private:
-    entityx::Entity player;
+       static entityx::Entity player;
 
-    bool moveLeft;
-    bool moveRight;
-
-    float speed;
+       static bool moveLeft;
+       static bool moveRight;
+       static float speed;
 
 public:
-    PlayerSystem(void)
-        : moveLeft(false), moveRight(false), speed(1.0f) {}
+       PlayerSystem(void);
 
        /**
         * Creates the player, adding it to the entity system.
         */
-       void create(void);
-       inline auto getId(void) const { return player.id(); }
+       static void create(void);
+       static inline auto getId(void)
+       { return player.id(); }
 
        /**
         * Configures events for use with the entity system.
@@ -68,20 +67,20 @@ public:
         * Gets the player's position.
         * @return the player's position
         */
-    vec2 getPosition(void) const;
+       static vec2 getPosition(void);
 
        /**
         * Sets the player's X coordinate.
         * @param x the x coordinate to give the player
         */
-       inline void setX(const float& x)
+       static inline void setX(const float& x)
        { player.component<Position>().get()->x = x; }
 
        /**
         * Gets the width of the player.
         * @return the player's width, according to its sprite
         */
-    inline float getWidth(void) const
+    static inline float getWidth(void) 
     { return game::entities.component<Solid>(player.id())->width; }
 };
 
index b74438dc31a224986e4f81b0609f1a220c725f9c..be9755f72ac18b078561ffc6c321be3f4fff8bd2 100644 (file)
@@ -37,7 +37,7 @@ private:
        /**
         * A list of all quests that are currently active.
         */
-       std::vector<Quest> current;
+       static std::vector<Quest> current;
 
 public:
        void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
@@ -49,28 +49,28 @@ public:
         * @param req retrieved from XML, list of what the quest wants
         * @return a possible error code
         */
-       int assign(std::string title, std::string desc, std::string req);
+       static int assign(std::string title, std::string desc, std::string req);
 
        /**
         * Drops a quest through its title.
         * @param title the quest's title
         * @return a possible error code
         */
-       int drop(std::string title);
+       static int drop(std::string title);
 
        /**
         * Finishes a quest through it's title.
         * @param title the quest's title
         * @return a possible error code
         */
-       int finish(std::string title);
+       static int finish(std::string title);
 
        /**
         * Returns true if the system is currently taking the quest.
         * @param title the quest's title
         * @return if the quest is active.
         */
-       bool hasQuest(std::string title);
+       static bool hasQuest(std::string title);
 };
 
 #endif // QUEST_HPP_
index 58a0cfa2e93c7fc88f32e653e7cbd606ed9c247c..c19a52da190681cc822dd9ef06e3df1cd12a7df4 100644 (file)
@@ -5,8 +5,7 @@
 
 #include <entityx/entityx.h>
 
-#include <config.hpp>
-#include <particle.hpp>
+#include <vector2.hpp>
 
 extern vec2 offset;
 
@@ -22,60 +21,16 @@ enum class Weather : unsigned char {
        count
 };
 
-constexpr const char *weatherStrings[] = {
-       "Sunny",
-       "Rainy",
-       "Snowy"
-};
-
 class WeatherSystem : public entityx::System<WeatherSystem> {
 private:
-       Weather weather;
+       static Weather weather;
 
 public:
-       WeatherSystem(Weather w = Weather::Sunny)
-               : weather(w) {}
-
-       void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override {
-               (void)en;
-               (void)ev;
-               (void)dt;
-
-               static auto& partSystem = *game::engine.getSystem<ParticleSystem>();
-               static int newPartDelay = 0; // TODO no
+       WeatherSystem(Weather w = Weather::Sunny);
 
-               switch (weather) {
-               case Weather::Sunny:
-                       break;
-               case Weather::Rainy:
-                       if (newPartDelay++ == 4) {
-                               newPartDelay = 0;
-                               partSystem.add(vec2(offset.x - game::SCREEN_WIDTH / 2 + randGet() % game::SCREEN_WIDTH,
-                                       offset.y + game::SCREEN_HEIGHT / 2 + 100),
-                                       ParticleType::Drop, 3000, 3);
-                       }
-                       break;
-               case Weather::Snowy:
-                       if (newPartDelay++ == 6) {
-                               newPartDelay = 0;
-                               partSystem.add(vec2(offset.x - game::SCREEN_WIDTH + randGet() % game::SCREEN_WIDTH * 2,
-                                       offset.y + game::SCREEN_HEIGHT / 2 + 50),
-                                       ParticleType::Confetti, 10000, 0);
-                       }
-                       break;
-               default:
-                       break;
-               }
-       }
+       void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
 
-       inline void setWeather(const std::string& w) {
-               for (int i = 0; i < static_cast<int>(Weather::count); i++) {
-                       if (w == weatherStrings[i]) {
-                               weather = static_cast<Weather>(i);
-                               return;
-                       }
-               }
-       }
+       static void setWeather(const std::string& w);
 };
 
 #endif // WEATHER_HPP_
index d53a2bf54fae17dcad34e1272357fa1e8d845795..36618e525f720ddeef362c416703d0c69151a97a 100644 (file)
@@ -23,22 +23,24 @@ private:
        /**
         * SDL's object for the window.
         */
-    SDL_Window *window;
+    static SDL_Window *window;
 
        /**
         * An OpenGL context, created when OpenGL is set up for use.
         */
-    SDL_GLContext glContext;
+    static SDL_GLContext glContext;
 
 public:
        WindowSystem(void);
 
-       void die(void);
+       static void die(void);
 
        void configure(entityx::EventManager &ev);
     void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override
        { (void)en; (void)ev; (void)dt; }
-       void render(void);
+
+       static void render(void);
+
        void receive(const WindowResizeEvent&); 
        void receive(const ScreenshotEvent&);
 };
index 2af464224611da15914d79c5c3c63609b28b2080..ac55b56d0872fe90372bf9265d78771649707ad0 100644 (file)
@@ -177,7 +177,7 @@ public:
 
        void fight(entityx::Entity entity);
 
-       void die(void);
+       static void die(void);
 };
 
 #endif // WORLD_HPP_
index 5cd4a4414aad499fa540eae96f30d473f5548a40..b6e5e24f0508b18e5656598b704ce847b5682b88 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -117,9 +117,9 @@ int main(int argc, char *argv[])
        /////////////////////////////
 
 
-       game::engine.getSystem<InventorySystem>()->add("Hunters Bow", 1);
-       game::engine.getSystem<InventorySystem>()->add("Wood Sword", 1);
-       game::engine.getSystem<InventorySystem>()->add("Arrow", 198);
+       InventorySystem::add("Hunters Bow", 1);
+       InventorySystem::add("Wood Sword", 1);
+       InventorySystem::add("Arrow", 198);
 
        std::list<SDL_Event> eventQueue;
 
@@ -188,8 +188,8 @@ int main(int argc, char *argv[])
 
     unloadTextures();
 
-       game::engine.getSystem<WorldSystem>()->die();
-       game::engine.getSystem<WindowSystem>()->die();
+       WorldSystem::die();
+       WindowSystem::die();
 
     return 0; // Calls everything passed to atexit
 }
index e91b4cd19b231158ccc650f4383b2a9817e1e3d1..f62763186d70649f2076522571140f250d5f30ed 100644 (file)
@@ -45,7 +45,7 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev,
                en.each<Health, Position, Solid>([&](entityx::Entity e, Health& health, Position& pos, Solid& dim) {
                        if (!e.has_component<Player>() && inrange(ppos.x, pos.x, pos.x + dim.width) && inrange(ppos.y, pos.y - 2, pos.y + dim.height)) {
                                health.health -= hit.damage;
-                               game::engine.getSystem<ParticleSystem>()->addMultiple(15, ParticleType::SmallBlast,
+                               ParticleSystem::addMultiple(15, ParticleType::SmallBlast,
                                        [&](){ return vec2(pos.x + dim.width / 2, pos.y + dim.height / 2); }, 300, 7);
                                die = !hit.pierce;
                        } else if (WorldSystem::isAboveGround(vec2(ppos.x, ppos.y - 5)))
@@ -69,7 +69,7 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev,
                                        if (inrange(a.pos.x, pos.x, pos.x + dim.width, HLINES(shortSlashLength)) &&
                                                inrange(a.pos.y, pos.y, pos.y + dim.height)) {
                                                h.health -= a.power;
-                                               game::engine.getSystem<ParticleSystem>()->addMultiple(15, ParticleType::DownSlash,
+                                               ParticleSystem::addMultiple(15, ParticleType::DownSlash,
                                                        [&](){ return vec2(pos.x + dim.width / 2, pos.y + dim.height / 2); }, 300, 7);
                                        }
                                }
index dcb1551141baee2911db710ec167630ce84db292..f5faf6b4b12dbf799b79bf7e0b31552873b9b136 100644 (file)
@@ -20,6 +20,9 @@
 
 using namespace std::literals::chrono_literals;
 
+std::string RenderSystem::loadTexString;
+Texture     RenderSystem::loadTexResult;
+
 static std::vector<std::string> randomDialog (readFileA("assets/dialog_en-us"));
 
 void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
@@ -50,7 +53,7 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
                                        fl = (direction.x < 0);
                        }
 
-                       auto ppos = game::engine.getSystem<PlayerSystem>()->getPosition();
+                       auto ppos = PlayerSystem::getPosition();
                        if (ppos.x > position.x && ppos.x < position.x + entity.component<Solid>()->width) {
                                if (entity.has_component<Aggro>()) {
                                        auto dim = entity.component<Solid>();
@@ -280,8 +283,7 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                                                auto ixml = exml->FirstChildElement("give");
                                                if (ixml != nullptr) {
                                                        do {
-                                                               game::engine.getSystem<InventorySystem>()->add(
-                                                                       ixml->StrAttribute("name"), ixml->IntAttribute("count"));
+                                                               InventorySystem::add(ixml->StrAttribute("name"), ixml->IntAttribute("count"));
                                                                ixml = ixml->NextSiblingElement();
                                                        } while (ixml != nullptr);
                                                }
@@ -289,7 +291,6 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                                                auto qxml = exml->FirstChildElement("quest");
                                                if (qxml != nullptr) {
                                                        const char *qname;
-                                                       auto qsys = game::engine.getSystem<QuestSystem>();
 
                                                        do {
                                                                // assign quest
@@ -297,14 +298,14 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                                                                if (qname != nullptr) {
                                                                        questAssignedText = qname;
                                                                        auto req = qxml->GetText();
-                                                                       qsys->assign(qname, qxml->StrAttribute("desc"), req ? req : "");
+                                                                       QuestSystem::assign(qname, qxml->StrAttribute("desc"), req ? req : "");
                                                                }
 
                                                                // check / finish quest
                                                                else {
                                                                        qname = qxml->Attribute("check");
                                                                        if (qname != nullptr) {
-                                                                               if (qname != nullptr && qsys->finish(qname) == 0) {
+                                                                               if (qname != nullptr && QuestSystem::finish(qname) == 0) {
                                                                                        d.index = 9999;
                                                                                } else {
                                                                                        UISystem::dialogBox(name.name, /*"", false,*/ "Finish my quest u nug");
index 970904b28245952c6cffeeeacce7e4856b83cf74..07b453cf17c5f7da76abf68ab84853703c23a9f2 100644 (file)
@@ -54,7 +54,7 @@ void Engine::init(void) {
     ui::initSounds();
        ui::menu::init();
        game::config::update();
-       getSystem<PlayerSystem>()->create();
+       PlayerSystem::create();
 }
 
 void Engine::update(entityx::TimeDelta dt)
index 761ca4300911c9405541f48de252f30402eddb9e..434eac6fbe7c29074f96cf032c046007f95183ef 100644 (file)
@@ -17,6 +17,15 @@ using namespace tinyxml2;
 
 extern vec2 offset;
 
+std::unordered_map<std::string, Item> InventorySystem::itemList;
+std::vector<InventoryEntry>           InventorySystem::items;
+vec2 InventorySystem::hotStart;
+vec2 InventorySystem::hotEnd;
+vec2 InventorySystem::fullStart;
+vec2 InventorySystem::fullEnd;
+int  InventorySystem::movingItem = -1;
+bool InventorySystem::fullInventory = false;
+
 inline bool isGoodEntry(const InventoryEntry& ie) {
        return (ie.item != nullptr) && (ie.count > 0);
 }
@@ -142,7 +151,7 @@ void InventorySystem::render(void)
                i.item->sprite.use();
                glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
 
-               auto pos = game::engine.getSystem<PlayerSystem>()->getPosition();
+               auto pos = PlayerSystem::getPosition();
                vec2 sta (pos.x, pos.y);
                vec2 end (sta + (i.item->sprite.getDim() * game::HLINE));
                GLfloat coords[18] = {
index a546c0c4feb3f71c82e77e2ece6d005a365b0b72..f2604a6fe4df81c8dd54167f8aed9a2d6662674d 100644 (file)
@@ -7,9 +7,12 @@
 
 #include <mutex>
 
+std::vector<Particle> ParticleSystem::parts;
+unsigned int          ParticleSystem::maximum;
+
 ParticleSystem::ParticleSystem(unsigned int max)
-       : maximum(max)
 {
+       maximum = max;
        parts.reserve(maximum);
 }
 
@@ -36,7 +39,7 @@ void ParticleSystem::render(void)
        constexpr auto entrySize = (6 * 5) * sizeof(GLfloat);
 
        static std::once_flag init;
-       std::call_once(init, [this](GLuint& vbo) {
+       std::call_once(init, [&entrySize](GLuint& vbo) {
                // generate VBO
                glGenBuffers(1, &vbo);
                glBindBuffer(GL_ARRAY_BUFFER, vbo);
@@ -168,7 +171,7 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e
        }
 }
 
-int ParticleSystem::getCount(void) const
+int ParticleSystem::getCount(void) 
 {
        return parts.size();
 }
index a4584791303504709d60f8d3a85533f07c8e4bca..0256190ccd4a252e6b1f316a7c02c20144a0c26e 100644 (file)
@@ -68,6 +68,15 @@ static const char *animationXML =
                </movement>\
        </Animation>";
 
+entityx::Entity PlayerSystem::player;
+bool  PlayerSystem::moveLeft = false;
+bool  PlayerSystem::moveRight = false;
+float PlayerSystem::speed = 1.0f;
+
+PlayerSystem::PlayerSystem(void)
+{
+}
+
 void PlayerSystem::create(void)
 {
        player = game::entities.create();
@@ -180,7 +189,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
                        if (game::canSprint)
                                speed = 2.0f;
 
-                       game::engine.getSystem<ParticleSystem>()->addMultiple(10, ParticleType::SmallBlast,
+                       ParticleSystem::addMultiple(10, ParticleType::SmallBlast,
                                [&](){ return vec2(loc.x, loc.y); }, 500, 7);
                } else if (kc == getControl(4)) {
                        speed = .5;
@@ -204,7 +213,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
        }
 }
 
-vec2 PlayerSystem::getPosition(void) const
+vec2 PlayerSystem::getPosition(void) 
 {
        auto& loc = *game::entities.component<Position>(player.id()).get();
     return vec2(loc.x, loc.y);
@@ -224,7 +233,7 @@ void PlayerSystem::receive(const UseItemEvent& uie)
                        loc.x += solid.width / 2, loc.y += solid.height / 2;
                        game::events.emit<AttackEvent>(loc, AttackType::ShortSlash, true);
                } else if (uie.item->type == "Bow") {
-                       if (game::engine.getSystem<InventorySystem>()->take("Arrow", 1)) {
+                       if (InventorySystem::take("Arrow", 1)) {
                                auto e = game::entities.create();
                                auto pos = getPosition();
                                e.assign<Position>(pos.x, pos.y + 10);
@@ -235,7 +244,7 @@ void PlayerSystem::receive(const UseItemEvent& uie)
                                e.assign<Visible>(-5);
                                e.assign<Physics>();
                                auto sprite = e.assign<Sprite>();
-                               auto tex = game::engine.getSystem<InventorySystem>()->getItem("Arrow");
+                               auto tex = InventorySystem::getItem("Arrow");
                                sprite->addSpriteSegment(SpriteData(tex.sprite), 0);
                                auto dim = HLINES(sprite->getSpriteSize());
                                e.assign<Solid>(dim.x, dim.y);
index 71a37fd464f617995206472cf55b554ffe508769..60172479dd1954f25a521f262b4c1b9aa7d88419 100644 (file)
@@ -6,6 +6,8 @@
 #include <inventory.hpp>
 #include <tokens.hpp>
 
+std::vector<Quest> QuestSystem::current;
+
 std::string& trim(std::string& s)
 {
        auto start = std::find_if(s.begin(), s.end(),
@@ -63,12 +65,12 @@ int QuestSystem::finish(std::string title)
                return -1;
 
        for (const auto& r : quest->reqs) {
-               if (!game::engine.getSystem<InventorySystem>()->take(r.first, r.second))
+               if (!InventorySystem::take(r.first, r.second))
                        return -1;
        }
 
        for (const auto& r : quest->rewards)
-               game::engine.getSystem<InventorySystem>()->add(r.first, r.second);
+               InventorySystem::add(r.first, r.second);
 
        drop(title);
 
index 8b9984798d1afc6e138fa7f9c7e9e65525605562..935e609d74069248e66a7b5529f051e531b7bef2 100644 (file)
@@ -132,9 +132,8 @@ void preRender(void)
        // set the ortho
        //
 
-       auto ps = game::engine.getSystem<PlayerSystem>();
-       auto ploc = ps->getPosition();
-       offset.x = ploc.x + ps->getWidth() / 2;
+       auto ploc = PlayerSystem::getPosition();
+       offset.x = ploc.x + PlayerSystem::getWidth() / 2;
 
        const auto& worldWidth = WorldSystem::getWidth();
        if (worldWidth < (int)SCREEN_WIDTH2 * 2)
@@ -178,20 +177,17 @@ void render(const int& fps)
        preRender();
 
        WorldSystem::render();
-
-       game::engine.getSystem<ParticleSystem>()->render();
-
-       game::engine.getSystem<RenderSystem>()->render();
-
-       game::engine.getSystem<InventorySystem>()->render();
+       ParticleSystem::render();
+       RenderSystem::render();
+       InventorySystem::render();
 
        // draw the debug overlay if desired
        if (ui::debug) {
-               auto pos = game::engine.getSystem<PlayerSystem>()->getPosition();
+               auto pos = PlayerSystem::getPosition();
                UISystem::putText(vec2(offset.x - game::SCREEN_WIDTH / 2, (offset.y + game::SCREEN_HEIGHT / 2) - FontSystem::getSize()),
                    "loc: %s\noffset: %s\nfps: %d\nticks: %d\npcount: %d\nxml: %s\nmem: %llukb (%d)",
                        pos.toString().c_str(), offset.toString().c_str(), fps,
-                       game::time::getTickCount(), game::engine.getSystem<ParticleSystem>()->getCount(),
+                       game::time::getTickCount(), ParticleSystem::getCount(),
                        WorldSystem::getXMLFile().c_str(), getUsedMem() / 1024, balance
                        );
        }
@@ -201,5 +197,5 @@ void render(const int& fps)
        //ui::drawFade();
        ui::draw();
        
-       game::engine.getSystem<WindowSystem>()->render();
+       WindowSystem::render();
 }
index d14b0a6a49f1d041f1477d3be045998f975e7788..e1e6eccc49d36ff472a389d063eef0bd110bf5e5 100644 (file)
@@ -965,7 +965,7 @@ void UISystem::render(void)
        if (!dialogText.empty()) {
                vec2 where (offset.x - 300, game::SCREEN_HEIGHT - 60);
                ui::drawNiceBox(vec2(where.x - 10, where.y - 200), vec2(where.x + 620, where.y + 20), -5.5f);
-               putString(where, dialogText, where.x + 600);
+               putString(where, ui::typeOut(dialogText), where.x + 600);
 
                if (!dialogOptions.empty()) {
                        float y = where.y - 180;
@@ -988,7 +988,7 @@ void UISystem::render(void)
        if (!importantText.empty()) {
                FontSystem::setFontSize(24);
                FontSystem::setFontZ(-9.0f);
-               putStringCentered(vec2(offset.x, 400), importantText);
+               putStringCentered(vec2(offset.x, 400), ui::typeOut(importantText));
                FontSystem::setFontZ(-6.0f);
                FontSystem::setFontSize(16);
        }
index 08d45e709783ff9d43486e829f280ab6247f4110..138a2813e03d8c736b843a696d040665b8e45b34 100644 (file)
@@ -29,7 +29,8 @@ void SDLReceiver::receive(const MainSDLEvent& mse)
        case SDL_KEYUP:
                if (currentMenu != nullptr && mse.event.key.keysym.sym == SDLK_ESCAPE) {
                        currentMenu->gotoParent();
-                       return;
+               } else {
+                       clicked = false;
                }
                break;
        default:
diff --git a/src/weather.cpp b/src/weather.cpp
new file mode 100644 (file)
index 0000000..59396d8
--- /dev/null
@@ -0,0 +1,61 @@
+#include <weather.hpp>
+
+#include <config.hpp>
+#include <random.hpp>
+#include <particle.hpp>
+
+constexpr const char *weatherStrings[] = {
+       "Sunny",
+       "Rainy",
+       "Snowy"
+};
+
+Weather WeatherSystem::weather;
+
+WeatherSystem::WeatherSystem(Weather w)
+{
+       weather = w;
+}
+
+void WeatherSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
+{
+       (void)en;
+       (void)ev;
+       (void)dt;
+
+       static int newPartDelay = 0; // TODO no
+
+       switch (weather) {
+       case Weather::Sunny:
+               break;
+       case Weather::Rainy:
+               if (newPartDelay++ == 4) {
+                       newPartDelay = 0;
+                       ParticleSystem::add(vec2(offset.x - game::SCREEN_WIDTH / 2 + randGet() % game::SCREEN_WIDTH,
+                               offset.y + game::SCREEN_HEIGHT / 2 + 100),
+                               ParticleType::Drop, 3000, 3);
+               }
+               break;
+       case Weather::Snowy:
+               if (newPartDelay++ == 6) {
+                       newPartDelay = 0;
+                       ParticleSystem::add(vec2(offset.x - game::SCREEN_WIDTH + randGet() % game::SCREEN_WIDTH * 2,
+                               offset.y + game::SCREEN_HEIGHT / 2 + 50),
+                               ParticleType::Confetti, 10000, 0);
+               }
+               break;
+       default:
+               break;
+       }
+}
+
+void WeatherSystem::setWeather(const std::string& w)
+{
+       for (int i = 0; i < static_cast<int>(Weather::count); i++) {
+               if (w == weatherStrings[i]) {
+                       weather = static_cast<Weather>(i);
+                       return;
+               }
+       }
+}
+
index df584be57f16a83f819eeb828561c9b68e23d722..af0f63b444a8dfbed0bf8fa70efa263f8427dd76 100644 (file)
@@ -9,6 +9,9 @@
 
 constexpr const char* WINDOW_TITLE  = "gamedev";
 
+SDL_Window*   WindowSystem::window;
+SDL_GLContext WindowSystem::glContext;
+
 WindowSystem::WindowSystem(void)
 {
     // attempt to initialize SDL
index 29f77a2117fb4483eb81a267592ca0b87c6951df..bf349739ab9e29233901cb26794c995c286cbe9f 100644 (file)
@@ -192,7 +192,7 @@ void WorldSystem::fight(entityx::Entity entity)
        door.assign<Portal>(exit);
 
        auto sprite = door.assign<Sprite>();
-       auto dtex = game::engine.getSystem<RenderSystem>()->loadTexture("assets/style/classic/door.png");
+       auto dtex = RenderSystem::loadTexture("assets/style/classic/door.png");
        sprite->addSpriteSegment(SpriteData(dtex), 0);
 
        auto dim = HLINES(sprite->getSpriteSize());
@@ -201,8 +201,6 @@ void WorldSystem::fight(entityx::Entity entity)
 
 void WorldSystem::load(const std::string& file)
 {
-       auto& render = *game::engine.getSystem<RenderSystem>();
-
        entityx::Entity entity;
 
        // check for empty file name
@@ -266,17 +264,16 @@ void WorldSystem::load(const std::string& file)
 
        //game::entities.reset();
        if (!savedEntities.empty()) {
-               savedEntities.emplace_back(game::engine.getSystem<PlayerSystem>()->getId());
+               savedEntities.emplace_back(PlayerSystem::getId());
                game::entities.each<Position>(
                        [&](entityx::Entity entity, Position& p) {
                        (void)p;
-                       if (std::find(savedEntities.begin(), savedEntities.end(), entity.id())
-                               == savedEntities.end())
+                       if (std::find(savedEntities.begin(), savedEntities.end(), entity.id()) == savedEntities.end())
                                entity.destroy();
                }, true);
        } else {
                game::entities.reset();
-               game::engine.getSystem<PlayerSystem>()->create();
+               PlayerSystem::create();
        }
 
        // iterate through tags
@@ -313,16 +310,15 @@ void WorldSystem::load(const std::string& file)
                                UserError("<house> can only be used inside <IndoorWorld>");
 
                        //world.indoorWidth = wxml->FloatAttribute("width");
-                       world.indoorTex = render.loadTexture(wxml->StrAttribute("texture")); // TODO winbloze lol
+                       world.indoorTex = RenderSystem::loadTexture(wxml->StrAttribute("texture")); // TODO winbloze lol
                        auto str = wxml->StrAttribute("texture");
-                       auto tex = render.loadTexture(str);
+                       auto tex = RenderSystem::loadTexture(str);
                        world.indoorTex = tex;
                }
 
                // weather tag
                else if (tagName == "weather") {
-                       game::engine.getSystem<WeatherSystem>()->setWeather(wxml->GetText());
-                       //setWeather(wxml->GetText());
+                       WeatherSystem::setWeather(wxml->GetText());
                }
 
                // link tags
@@ -1092,7 +1088,7 @@ void WorldSystem::detect(entityx::TimeDelta dt)
                                vel.y = 0;
                                if (!vel.grounded) {
                                        vel.grounded = true;
-                                       game::engine.getSystem<ParticleSystem>()->addMultiple(20, ParticleType::SmallPoof,
+                                       ParticleSystem::addMultiple(20, ParticleType::SmallPoof,
                                                [&](){ return vec2(loc.x + randGet() % static_cast<int>(dim.width), loc.y);}, 500, 30);
                                }
                        }
@@ -1101,11 +1097,9 @@ void WorldSystem::detect(entityx::TimeDelta dt)
 
                // insure that the entity doesn't fall off either edge of the world.
         if (loc.x < world.startX) {
-                       std::cout << "Left!\n";
                        vel.x = 0;
                        loc.x = world.startX + HLINES(0.5f);
                } else if (loc.x + dim.width + game::HLINE > -(static_cast<int>(world.startX))) {
-                       std::cout << "Right\n";
                        vel.x = 0;
                        loc.x = -(static_cast<int>(world.startX)) - dim.width - game::HLINE;
                }
@@ -1120,7 +1114,7 @@ void WorldSystem::goWorldRight(Position& p, Solid &d)
                while (waitToSwap)
                        std::this_thread::sleep_for(1ms);
                load(world.toRight);
-               game::engine.getSystem<PlayerSystem>()->setX(world.startX + HLINES(10));
+               PlayerSystem::setX(world.startX + HLINES(10));
                UISystem::fadeToggle();
        }
 }
@@ -1133,7 +1127,7 @@ void WorldSystem::goWorldLeft(Position& p)
                while (waitToSwap)
                        std::this_thread::sleep_for(1ms);
                load(world.toLeft);
-               game::engine.getSystem<PlayerSystem>()->setX(world.startX * -1 - HLINES(15));
+               PlayerSystem::setX(world.startX * -1 - HLINES(15));
                UISystem::fadeToggle();
        }
 }
index 5c36eb94870120c3facd2702d02c12a5f99614ef..b2292c857a73569f8c59597e42a4a35ddda660ab 100644 (file)
@@ -58,7 +58,7 @@
        <Visible value="0.2" />
        <Sprite>
                <frame>
-                       <src limb="0" offset="0,0" size="192,331" drawOffset="0,0">assets/nug.png</src>
+                       <src limb="0" offset="0,0" size="48,24" drawOffset="0,0">assets/skirl.png</src>
                </frame>
        </Sprite>
        <Direction />