From 17756834e0e869a1de0b66707db4b2e4aba4b4e7 Mon Sep 17 00:00:00 2001 From: Joseph Aquino Date: Fri, 19 Dec 2025 16:00:48 -0500 Subject: [PATCH] small refactor --- src/Physics.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Physics.cpp b/src/Physics.cpp index 0dccd2a..7ab4ead 100644 --- a/src/Physics.cpp +++ b/src/Physics.cpp @@ -4,6 +4,7 @@ #include + sf::Vector2f getOverlap(const sf::FloatRect first, const sf::FloatRect second) { const float deltaX = std::abs(second.position.x - first.position.x); @@ -14,18 +15,24 @@ sf::Vector2f getOverlap(const sf::FloatRect first, const sf::FloatRect second) return {resultX, resultY}; } +enum +{ + left, + right +}; + sf::Vector2f velocityInRandomDir(const float speed_in) { - const bool leftOrRight{(bool)Random::get(0,1)}; + const int side{Random::get(0,1)}; // get angle within certain ranges so that the ball does not // start moving straight side to side or up and down - if (leftOrRight) + if (side == left) {// left const sf::Angle angle = sf::degrees((float)Random::get(220, 255)); return sf::Vector2f{speed_in * std::cos(angle.asRadians()), speed_in * std::sin(angle.asRadians())}; } - else if (!leftOrRight) + else if (side == right) {// right const sf::Angle angle = sf::degrees((float)Random::get(285, 315)); return sf::Vector2f{speed_in * std::cos(angle.asRadians()), speed_in * std::sin(angle.asRadians())};