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())};