summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorDmitrii Ubskii <ubskydm@gmail.com>2021-05-16 23:54:39 +0300
committerLinus Groh <mail@linusgroh.de>2021-05-18 18:58:07 +0100
commit9c963fa17b699005660c21e3d9e22ccdaf9f709a (patch)
tree4de6179471ad67bab4d33c54911d4b495a4a8689 /Userland
parent9a7aac1c6a7c4347af593f1aee69b1724f2ce177 (diff)
downloadserenity-9c963fa17b699005660c21e3d9e22ccdaf9f709a.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Games/Pong/Game.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/Userland/Games/Pong/Game.cpp b/Userland/Games/Pong/Game.cpp
index 1ba806c548..83e7b0cb21 100644
--- a/Userland/Games/Pong/Game.cpp
+++ b/Userland/Games/Pong/Game.cpp
@@ -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,