From: drumsetmonkey Date: Thu, 28 Apr 2016 15:49:17 +0000 (-0400) Subject: Sword Swinging X-Git-Url: https://code.bitgloo.com/?a=commitdiff_plain;h=4f0dff18e4680d9bb4e7efc9cffdb0b63937533c;p=clyne%2Fgamedev.git Sword Swinging --- diff --git a/src/inventory.cpp b/src/inventory.cpp index 78502a7..ab31277 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -100,7 +100,7 @@ void items(void) int Inventory::addItem(std::string name, uint count) { - std::cout << "Adding: " << count << name << "\'s" << std::endl; + std::cout << "Adding: " << count << " " << name << std::endl; for (uint i = 0; i < ItemMap.size(); i++) { if (strCaseCmp(ItemMap[i]->name, name)) { for (auto &it : Items) { diff --git a/src/items.cpp b/src/items.cpp index 403c49e..b86abf7 100644 --- a/src/items.cpp +++ b/src/items.cpp @@ -19,10 +19,21 @@ int BaseItem::useItem() int Sword::useItem() { std::cout << "Swing!" << std::endl; - if (player->left) - rotation += 10.0f; - else - rotation -= 10.0f; + std::thread([this]{ + player->inv->usingi = true; + bool swing = true; + float coef = 0.0f; + + while (swing) { + coef += .01f; + if (player->left) + rotation = coef; + else + rotation = -coef; + } + player->inv->usingi = false; + }).detach(); + return 0; } diff --git a/src/ui.cpp b/src/ui.cpp index 48c260b..0f81f34 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -964,7 +964,8 @@ EXIT: } else { // left click uses item if (e.button.button & SDL_BUTTON_LEFT) - player->inv->useCurrent(); + if(!player->inv->usingi) + player->inv->useCurrent(); } if(mouse.x > player->loc.x && mouse.x < player->loc.x + player->width &&