diff --git a/Games/Breakout/Game.cpp b/Games/Breakout/Game.cpp index e69b2dab6a..7ec8c3a975 100644 --- a/Games/Breakout/Game.cpp +++ b/Games/Breakout/Game.cpp @@ -168,9 +168,18 @@ void Game::mousemove_event(GUI::MouseEvent& event) void Game::reset_ball() { + int position_x_min = (game_width / 2) - 50; + int position_x_max = (game_width / 2) + 50; + int position_x = arc4random() % (position_x_max - position_x_min + 1) + position_x_min; + int position_y = 200; + int velocity_x = arc4random() % 3 + 1; + int velocity_y = 3 + (3 - velocity_x); + if (arc4random() % 2) + velocity_x = velocity_x * -1; + m_ball = {}; - m_ball.position = { 150, 200 }; - m_ball.velocity = { 3, 3 }; + m_ball.position = { position_x, position_y }; + m_ball.velocity = { velocity_x, velocity_y }; } void Game::hurt()