Breakout: randomize ball start trajectory and velocity

This commit is contained in:
Brendan Coles 2020-12-15 11:59:20 +00:00 committed by Andreas Kling
parent d410449d87
commit e3114667bc
Notes: sideshowbarker 2024-07-19 00:49:11 +09:00

View file

@ -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()