diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/attack.hpp | 39 | ||||
-rw-r--r-- | include/components.hpp | 6 | ||||
-rw-r--r-- | include/vector2.hpp | 4 |
3 files changed, 48 insertions, 1 deletions
diff --git a/include/attack.hpp b/include/attack.hpp new file mode 100644 index 0000000..412694e --- /dev/null +++ b/include/attack.hpp @@ -0,0 +1,39 @@ +#ifndef FIGHT_HPP_ +#define FIGHT_HPP_ + +#include <entityx/entityx.h> + +#include <forward_list> + +#include <vector2.hpp> + +enum class AttackType : char { + ShortSlash, + LongSlash +}; + +struct AttackEvent { + AttackEvent(vec2 p, AttackType at, int pow = 10) + : pos(p), type(at), power(pow) {} + + vec2 pos; + AttackType type; + int power; +}; + +class AttackSystem : public entityx::System<AttackSystem>, public entityx::Receiver<AttackSystem> { +private: + std::forward_list<AttackEvent> attacks; + +public: + explicit AttackSystem() = default; + + void configure(entityx::EventManager& ev) { + ev.subscribe<AttackEvent>(*this); + } + + void receive(const AttackEvent& ae); + void update(entityx::EntityManager& en, entityx::EventManager& ev, entityx::TimeDelta dt) override; +}; + +#endif // FIGHT_HPP_ diff --git a/include/components.hpp b/include/components.hpp index 541f0f8..0fb8ec6 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -172,7 +172,9 @@ struct Health : public Component { (void)imp; (void)def; // TODO - health = maxHealth = 1; + if (def->QueryIntAttribute("value", &health) != XML_NO_ERROR) + health = 1; + maxHealth = health; } }; @@ -208,6 +210,8 @@ struct Name : public Component { } }; +struct Player {}; + struct ItemDrop { ItemDrop(InventoryEntry& ie) : item(ie) {} diff --git a/include/vector2.hpp b/include/vector2.hpp index c1148da..828654c 100644 --- a/include/vector2.hpp +++ b/include/vector2.hpp @@ -84,6 +84,10 @@ struct vector2 { return (x < v.x) && (y < v.y); } + bool operator<=(const T& n) const { + return (x <= n) && (y <= n); + } + // other functions std::string toString(void) const { return "(" + std::to_string(x) + ", " + std::to_string(y) + ")"; |