Breakout: randomize ball start trajectory and velocity
This commit is contained in:
parent
d410449d87
commit
e3114667bc
Notes:
sideshowbarker
2024-07-19 00:49:11 +09:00
Author: https://github.com/bcoles Commit: https://github.com/SerenityOS/serenity/commit/e3114667bcc Pull-request: https://github.com/SerenityOS/serenity/pull/4422
1 changed files with 11 additions and 2 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue