summaryrefslogtreecommitdiff
path: root/Games/Breakout
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-11-10 14:13:09 +0100
committerAndreas Kling <kling@serenityos.org>2020-11-10 14:32:45 +0100
commit959038d410ea0fbc9c592f6cb7a5dce763768c39 (patch)
tree3b9ea32ecf1a52bef4f534c2975ee0daaadb6769 /Games/Breakout
parent844c2e1f3b7efddd427f055fa9dd1cd543aa0741 (diff)
downloadserenity-959038d410ea0fbc9c592f6cb7a5dce763768c39.zip
Breakout: Change ball x velocity depending on where it hits paddle
This makes the game less deterministic and more fun. The "physics" definitely feel a little goofy, and I'm sure they can be greatly improved, but still it's already better. :^)
Diffstat (limited to 'Games/Breakout')
-rw-r--r--Games/Breakout/Game.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/Games/Breakout/Game.cpp b/Games/Breakout/Game.cpp
index 30e4f065fb..21b7405972 100644
--- a/Games/Breakout/Game.cpp
+++ b/Games/Breakout/Game.cpp
@@ -198,6 +198,10 @@ void Game::tick()
if (new_ball.rect().intersects(m_paddle.rect)) {
new_ball.position.set_y(m_ball.y());
new_ball.velocity.set_y(new_ball.velocity.y() * -1);
+
+ float distance_to_middle_of_paddle = new_ball.x() - m_paddle.rect.center().x();
+ float relative_impact_point = distance_to_middle_of_paddle / m_paddle.rect.width();
+ new_ball.velocity.set_x(relative_impact_point * 7);
}
for (auto& brick : m_bricks) {