aboutsummaryrefslogtreecommitdiffstats
path: root/src/player.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2017-03-17 22:17:30 -0400
committerClyne Sullivan <tullivan99@gmail.com>2017-03-17 22:17:30 -0400
commit19ade83b74aa66c80129409d97c2c98fa8b8534c (patch)
treeed8fdfb53a302d1e236cb74b7f0413f83f55020d /src/player.cpp
parentbf01660ab468f49d63a133c28131ab21bba3a1a1 (diff)
bow & arrow draft
Diffstat (limited to 'src/player.cpp')
-rw-r--r--src/player.cpp40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/player.cpp b/src/player.cpp
index 3d959ea..2fb7c44 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -211,10 +211,40 @@ vec2 PlayerSystem::getPosition(void) const
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);
+ static std::atomic_bool cool (true);
+
+ if (cool.load()) {
+ if (uie.item->sound != nullptr)
+ Mix_PlayChannel(0, uie.item->sound, 0);
+
+ 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);
+ } else if (uie.item->type == "Bow") {
+ if (game::engine.getSystem<InventorySystem>()->take("Arrow", 1)) {
+ auto e = game::entities.create();
+ auto pos = getPosition();
+ e.assign<Position>(pos.x, pos.y + 10);
+
+ auto angle = std::atan2(uie.curs.y - pos.y, uie.curs.x - pos.x);
+ e.assign<Direction>(1 * std::cos(angle), 1 * std::sin(angle));
+
+ e.assign<Visible>(-5);
+ e.assign<Physics>();
+ auto sprite = e.assign<Sprite>();
+ auto tex = game::engine.getSystem<InventorySystem>()->getItem("Arrow");
+ sprite->addSpriteSegment(SpriteData(tex.sprite), 0);
+ auto dim = HLINES(sprite->getSpriteSize());
+ e.assign<Solid>(dim.x, dim.y);
+ }
+ }
+
+ /*cool.store(false);
+ std::thread([&](void) {
+ std::this_thread::sleep_for(std::chrono::milliseconds(uie.item->cooldown));
+ cool.store(true);
+ }).detach();*/
}
}