mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:37:44 +00:00
Pong: Make the game winnable
- Make the ball chill out a bit by reducing its x velocity by 1. - Make the AI dumber. It now relaxes until the ball is coming towards it and is in its half of the court.
This commit is contained in:
parent
9a7aac1c6a
commit
9c963fa17b
1 changed files with 8 additions and 1 deletions
|
@ -130,7 +130,7 @@ void Game::reset_ball(int serve_to_player)
|
|||
int position_y = get_random<u32>() % (position_y_max - position_y_min + 1) + position_y_min;
|
||||
int position_x = (game_height / 2);
|
||||
int velocity_y = get_random<u32>() % 3 + 1;
|
||||
int velocity_x = 5 + (5 - velocity_y);
|
||||
int velocity_x = 4 + (5 - velocity_y);
|
||||
if (get_random<u32>() % 2)
|
||||
velocity_y = velocity_y * -1;
|
||||
if (serve_to_player == 2)
|
||||
|
@ -170,6 +170,13 @@ void Game::calculate_move()
|
|||
int player_2_paddle_top = m_player2_paddle.rect.top();
|
||||
int player_2_paddle_bottom = m_player2_paddle.rect.bottom();
|
||||
|
||||
if (m_ball.velocity.x() > 0 || m_ball.x() > game_width / 2) {
|
||||
// The ball is in the opponent's court, relax.
|
||||
m_player2_paddle.moving_up = false;
|
||||
m_player2_paddle.moving_down = false;
|
||||
return;
|
||||
}
|
||||
|
||||
int ball_position = m_ball.y() + m_ball.radius;
|
||||
|
||||
// AI paddle begins moving when the ball crosses the begin_trigger,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue