]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Sword Swinging
authordrumsetmonkey <abelleisle@roadrunner.com>
Thu, 28 Apr 2016 15:49:17 +0000 (11:49 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Thu, 28 Apr 2016 15:49:17 +0000 (11:49 -0400)
src/inventory.cpp
src/items.cpp
src/ui.cpp

index 78502a78c4a0f0035786d1e55602c37c27f8dd2d..ab31277b550983e38c9210ef42bfd54ed67f73bf 100644 (file)
@@ -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) {
index 403c49efed15a2e8fd7dc5a0404c2782c0a82e8f..b86abf70297d658f7954c5d4d8fcacfffa0bc427 100644 (file)
@@ -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;
 }
 
index 48c260b0fa2a9e3eaa7f62af40388609b240e50a..0f81f34d25b66a90836b91b1220d0b489958018d 100644 (file)
@@ -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 &&