diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2017-07-23 10:47:10 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2017-07-23 10:47:10 -0400 |
commit | 9e540db7d6492168cadcafddbf145ffdd7b21981 (patch) | |
tree | 8019a7a67e66a5ec87ad7872278e8ee92431251a /include | |
parent | 215e5ee6ce089c3e0d5be28fd816bc7031b6acab (diff) |
source cleanup; beginning of custom attacks
Diffstat (limited to 'include')
-rw-r--r-- | include/attack.hpp | 25 | ||||
-rw-r--r-- | include/inventory.hpp | 39 | ||||
-rw-r--r-- | include/vector2.hpp | 10 |
3 files changed, 29 insertions, 45 deletions
diff --git a/include/attack.hpp b/include/attack.hpp index 0ab5138..2074ac2 100644 --- a/include/attack.hpp +++ b/include/attack.hpp @@ -1,5 +1,5 @@ -#ifndef FIGHT_HPP_ -#define FIGHT_HPP_ +#ifndef ATTACK_HPP_ +#define ATTACK_HPP_ #include <entityx/entityx.h> @@ -7,19 +7,22 @@ #include <vector2.hpp> -enum class AttackType : char { - ShortSlash, - LongSlash, +struct Attack { + int power; + vec2 offset; + vec2 range; + vec2 vel; // TODO use + vec2 accel; // TODO use }; struct AttackEvent { - AttackEvent(vec2 p, AttackType at, bool fp, int pow = 10) - : pos(p), type(at), fromplayer(fp), power(pow) {} + AttackEvent(vec2 p, Attack at, bool fp) + : pos(p), attack(at), fromplayer(fp) {} vec2 pos; - AttackType type; + Attack attack; + bool fromplayer; - int power; }; class AttackSystem : public entityx::System<AttackSystem>, public entityx::Receiver<AttackSystem> { @@ -27,8 +30,6 @@ private: std::forward_list<AttackEvent> attacks; public: - explicit AttackSystem() = default; - void configure(entityx::EventManager& ev) { ev.subscribe<AttackEvent>(*this); } @@ -37,4 +38,4 @@ public: void update(entityx::EntityManager& en, entityx::EventManager& ev, entityx::TimeDelta dt) override; }; -#endif // FIGHT_HPP_ +#endif // ATTACK_HPP_ diff --git a/include/inventory.hpp b/include/inventory.hpp index 1de22dc..ac87f38 100644 --- a/include/inventory.hpp +++ b/include/inventory.hpp @@ -16,6 +16,7 @@ #include <tinyxml2.h> using namespace tinyxml2; +#include <attack.hpp> #include <events.hpp> #include <texture.hpp> @@ -33,36 +34,12 @@ struct Item { int cooldown; Item(void) - : value(0), stackSize(1) {} + : value(0), stackSize(1), cooldown(0) {} - /** - * Constructs an item from XML. - * @param the xml element (<item />) - */ - Item(XMLElement* e) { - name = e->StrAttribute("name"); - type = e->StrAttribute("type"); - - value = 0; - e->QueryIntAttribute("value", &value); - stackSize = 1; - e->QueryIntAttribute("maxStackSize", &stackSize); - - sprite = Texture(e->StrAttribute("sprite")); - - if (e->Attribute("sound") != nullptr) - sound = Mix_LoadWAV(e->Attribute("sound")); - else - sound = nullptr; - - cooldown = 250; - e->QueryIntAttribute("cooldown", &cooldown); - } - - ~Item(void) { + /*~Item(void) { if (sound != nullptr) Mix_FreeChunk(sound); - } + }*/ }; /** @@ -80,11 +57,12 @@ struct InventoryEntry { }; struct UseItemEvent { - Item* item; vec2 curs; + Item* item; + Attack* attack; - UseItemEvent(Item* i, vec2 c) - : item(i), curs(c) {} + UseItemEvent(vec2 c, Item* i, Attack* a = nullptr) + : curs(c), item(i), attack(a) {} }; /** @@ -100,6 +78,7 @@ private: constexpr static unsigned int rowSize = 8; static std::unordered_map<std::string, Item> itemList; + static std::unordered_map<std::string, Attack> attackList; static std::vector<InventoryEntry> items; static vec2 hotStart; diff --git a/include/vector2.hpp b/include/vector2.hpp index 77ee7e7..5c9f9e1 100644 --- a/include/vector2.hpp +++ b/include/vector2.hpp @@ -24,9 +24,13 @@ struct vector2 { } vector2<T>& operator=(const std::string& s) { - auto comma = s.find(','); - x = std::stoi(s.substr(0, comma)); - y = std::stoi(s.substr(comma + 1)); + if (s.empty()) { + x = y = 0; + } else { + auto comma = s.find(','); + x = std::stoi(s.substr(0, comma)); + y = std::stoi(s.substr(comma + 1)); + } return *this; } |