diff options
Diffstat (limited to 'src/items.cpp')
-rw-r--r-- | src/items.cpp | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/src/items.cpp b/src/items.cpp index f0b2f84..180c5fa 100644 --- a/src/items.cpp +++ b/src/items.cpp @@ -104,25 +104,42 @@ int Arrow::useItem() int Bow::useItem() { - float rot = atan(sqrt(pow(ui::mouse.y-(player->loc.y + player->height),2)/pow(ui::mouse.x-player->loc.x,2))); - float speed = 1.0; - float vx = speed * cos(rot); - float vy = speed * sin(rot); - - ui::mouse.x < player->loc.x ? vx *= -1 : vx *= 1; - ui::mouse.y < player->loc.y + player->height ? vy *= -1 : vy *= 1; + if (inUse()) + return -1; - currentWorld->addParticle( player->loc.x, // x - player->loc.y + player->height, // y - HLINES(3), // width - HLINES(3), // height - vx, // vel.x - vy, // vel.y - { 139, 69, 19 }, // RGB color - 2500 // duration (ms) - ); + std::thread([this](void) { + setUse(true); + static Particles* part = nullptr; + + if (part == nullptr) { + float rot = atan(sqrt(pow(ui::mouse.y-(player->loc.y + player->height),2)/pow(ui::mouse.x-player->loc.x,2))); + float speed = 1.0; + float vx = speed * cos(rot); + float vy = speed * sin(rot); + + vx *= (ui::mouse.x < player->loc.x) ? -1 : 1; + vy *= (ui::mouse.y < player->loc.y + player->height) ? -1 : 1; + + currentWorld->addParticle(player->loc.x, // x + player->loc.y + player->height, // y + HLINES(3), // width + HLINES(3), // height + vx, // vel.x + vy, // vel.y + {139, 69, 19}, // RGB color + 2500 // duration (ms) + ); + part = ¤tWorld->particles.back(); + } else { + if (part->vel.x < 0.05 && part->vel.y < 0.05) { + part->duration = 0; + part = nullptr; + } + } + setUse(false); + }).detach(); return 0; } |