From 1ac412a5496fb6c63c47f199dfc7facd5f4c080a Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 20 Jan 2017 10:32:08 -0500 Subject: item drop, pick up --- src/inventory.cpp | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) (limited to 'src/inventory.cpp') diff --git a/src/inventory.cpp b/src/inventory.cpp index 83bdeb2..fd844f5 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -1,6 +1,8 @@ #include #include +#include +#include #include #include #include @@ -126,12 +128,26 @@ void InventorySystem::render(void) void InventorySystem::receive(const MouseClickEvent &mce) { - int end = fullInventory ? items.size() : hotbarSize; - movingItem = -1; - for (int i = 0; i < end; i++) { - if (mce.position > items[i].loc && mce.position < items[i].loc + entrySize) { - movingItem = i; - break; + if (mce.button == SDL_BUTTON_RIGHT) { + game::entities.each([&](entityx::Entity e, ItemDrop& id) { + auto& posComp = *e.component(); + auto& dimComp = *e.component(); + vec2 sta (posComp.x, posComp.y); + vec2 end (sta.x + dimComp.width, sta.y + dimComp.height); + + if (mce.position > sta && mce.position < end) { + add(id.item.item->name, id.item.count); + e.destroy(); + } + }); + } else { + int end = fullInventory ? items.size() : hotbarSize; + movingItem = -1; + for (int i = 0; i < end; i++) { + if (mce.position > items[i].loc && mce.position < items[i].loc + entrySize) { + movingItem = i; + break; + } } } } @@ -149,9 +165,27 @@ void InventorySystem::receive(const MouseReleaseEvent &mre) items[movingItem].item = nullptr; items[movingItem].count = 0; } - break; + + movingItem = -1; + return; } } + + auto e = game::entities.create(); + e.assign(mre.position.x, mre.position.y); + e.assign(0, 1); + e.assign(items[movingItem]); + e.assign(); + e.component()->addSpriteSegment( + SpriteData(items[movingItem].item->sprite), vec2(0, 0)); + auto dim = items[movingItem].item->sprite.getDim(); + e.assign(HLINES(dim.x), HLINES(dim.y)); + e.assign(); + e.assign(); + + items[movingItem].item = nullptr; + items[movingItem].count = 0; + movingItem = -1; } } -- cgit v1.2.3