diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2017-03-14 21:50:17 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2017-03-14 21:50:17 -0400 |
commit | bf01660ab468f49d63a133c28131ab21bba3a1a1 (patch) | |
tree | d1b6ef1920ae755ccd0c2b2562e2b988458182ec /src/player.cpp | |
parent | ba651a82d585c181e9632fadba5bb4d683842d44 (diff) |
good item using
Diffstat (limited to 'src/player.cpp')
-rw-r--r-- | src/player.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/player.cpp b/src/player.cpp index 0a85459..3d959ea 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -97,6 +97,7 @@ void PlayerSystem::configure(entityx::EventManager &ev) { ev.subscribe<KeyUpEvent>(*this); ev.subscribe<KeyDownEvent>(*this); + ev.subscribe<UseItemEvent>(*this); } void PlayerSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) { @@ -200,8 +201,6 @@ void PlayerSystem::receive(const KeyDownEvent &kde) } else if (kc == SDLK_t) { game::time::tick(50); } - if (kc == SDLK_j) - game::events.emit<AttackEvent>(vec2(loc.x, loc.y), AttackType::ShortSlash); } vec2 PlayerSystem::getPosition(void) const @@ -209,3 +208,13 @@ vec2 PlayerSystem::getPosition(void) const auto& loc = *game::entities.component<Position>(player.id()).get(); return vec2(loc.x, loc.y); } + +void PlayerSystem::receive(const UseItemEvent& uie) +{ + if (uie.item->type == "Sword") { + auto loc = getPosition(); + auto &solid = *player.component<Solid>().get(); + loc.x += solid.width / 2, loc.y += solid.height / 2; + game::events.emit<AttackEvent>(loc, AttackType::ShortSlash); + } +} |