small refactor
This commit is contained in:
parent
197a3bcfd5
commit
17756834e0
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <Random.h>
|
||||
|
||||
|
||||
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())};
|
||||
|
|
|
|||
Loading…
Reference in New Issue