mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-11 01:06:01 +03:00
Breakout: Improve collision response between ball and paddle
When the ball hits the side of the paddle, it would get stuck because the paddle moves faster than the ball. This commit forces the post- collision vertical velocity of the ball to be going up and makes sure that new ball's y-position is higher than in the previous frame.
This commit is contained in:
parent
d0245b5e6b
commit
61f573fa67
Notes:
sideshowbarker
2024-07-18 04:19:32 +09:00
Author: https://github.com/damienfir 🔰 Commit: https://github.com/SerenityOS/serenity/commit/61f573fa672 Pull-request: https://github.com/SerenityOS/serenity/pull/9938 Reviewed-by: https://github.com/AtkinsSJ ✅
@ -266,8 +266,10 @@ void Game::tick()
|
||||
update(enclosing_int_rect(new_ball.rect()));
|
||||
|
||||
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);
|
||||
if (m_ball.y() < new_ball.y()) {
|
||||
new_ball.position.set_y(m_ball.y());
|
||||
}
|
||||
new_ball.velocity.set_y(fabs(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();
|
||||
|
Loading…
Reference in New Issue
Block a user