From 8f586169c1b5f7f124dcc639ab575b4ec6e8d709 Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Thu, 18 Apr 2024 06:04:13 +0200 Subject: [PATCH] Check hit to start moving the position --- inc/App.hpp | 1 + src/App.cpp | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/inc/App.hpp b/inc/App.hpp index 2c0ce3f..440c132 100644 --- a/inc/App.hpp +++ b/inc/App.hpp @@ -23,4 +23,5 @@ private: Vector2 mouseStart; float len; float ofset; + bool validHit = false; }; diff --git a/src/App.cpp b/src/App.cpp index 483c04a..5498ce0 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -29,11 +29,12 @@ void App::update() if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { mouseStart = GetMousePosition(); + validHit = CheckCollisionPointRec(mouseStart, destA); len = Vector2Distance(mouseStart, {destB.x, destB.y}); ofset = std::atan2(destB.x - mouseStart.x, destB.y - mouseStart.y); } - if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) + if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) && validHit) { Vector2 mousePosition = GetMousePosition(); float dist = mousePosition.x - mouseStart.x; @@ -44,7 +45,7 @@ void App::update() destA.y = newCenter.y + mousePosition.y; } - if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) + if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT) && validHit) { canvases[1 - pos].newGen(); pos = 1 - pos;