diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2017-03-23 07:53:59 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2017-03-23 07:53:59 -0400 |
commit | 16836bb93bf57f01f416d3a0a55d0716dcf50c94 (patch) | |
tree | 907aa7768130e954502efb8db0c3bec828b83790 | |
parent | 2e67f6d04f79a3b9338466d289df0074cf4c454e (diff) |
arrows die, do damage
-rw-r--r-- | include/components.hpp | 12 | ||||
-rw-r--r-- | main.cpp | 2 | ||||
-rw-r--r-- | src/player.cpp | 1 | ||||
-rw-r--r-- | src/world.cpp | 6 |
4 files changed, 20 insertions, 1 deletions
diff --git a/include/components.hpp b/include/components.hpp index 3f06867..fe56a88 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -610,6 +610,18 @@ struct Aggro : public Component { } }; +struct Hit : public Component { + Hit(int d) + : damage(d) {} + + int damage; + + void fromXML(XMLElement* imp, XMLElement* def) final { + (void)imp; + (void)def; + } +}; + /** * SYSTEMS */ @@ -119,7 +119,7 @@ int main(int argc, char *argv[]) game::engine.getSystem<InventorySystem>()->add("Wood Sword", 1); game::engine.getSystem<InventorySystem>()->add("Hunters Bow", 1); - game::engine.getSystem<InventorySystem>()->add("Arrow", 40); + game::engine.getSystem<InventorySystem>()->add("Arrow", 198); std::list<SDL_Event> eventQueue; diff --git a/src/player.cpp b/src/player.cpp index 2fb7c44..1908af4 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -238,6 +238,7 @@ void PlayerSystem::receive(const UseItemEvent& uie) sprite->addSpriteSegment(SpriteData(tex.sprite), 0); auto dim = HLINES(sprite->getSpriteSize()); e.assign<Solid>(dim.x, dim.y); + e.assign<Hit>(10); } } diff --git a/src/world.cpp b/src/world.cpp index 9a47576..c41ab2a 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -14,6 +14,7 @@ using namespace std::literals::chrono_literals; using namespace tinyxml2; // game headers +#include <attack.hpp> #include <common.hpp> #include <components.hpp> #include <debug.hpp> @@ -1140,6 +1141,11 @@ void WorldSystem::detect(entityx::TimeDelta dt) } else { loc.y = data[line].groundHeight - 0.001f * dt; vel.y = 0; + if (e.has_component<Hit>()) { + game::events.emit<AttackEvent>(vec2(loc.x, loc.y), + AttackType::ShortSlash, e.component<Hit>()->damage); + e.destroy(); + } if (!vel.grounded) { vel.grounded = true; game::engine.getSystem<ParticleSystem>()->addMultiple(20, ParticleType::SmallPoof, |