From 0bf927a824bf54b660089990cbb3a56763bb4634 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 9 Nov 2020 13:15:30 +0100 Subject: [PATCH] Breakout: Use the pending new ball rect for brick collision testing Otherwise the ball will bounce one frame *after* hitting a brick. --- Games/Breakout/Game.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Games/Breakout/Game.cpp b/Games/Breakout/Game.cpp index 8588cac726..6ae68ff8a9 100644 --- a/Games/Breakout/Game.cpp +++ b/Games/Breakout/Game.cpp @@ -204,10 +204,10 @@ void Game::tick() for (auto& brick : m_bricks) { if (brick.dead) continue; - if (m_ball.rect().intersects(brick.rect)) { + if (new_ball.rect().intersects(brick.rect)) { brick.dead = true; - auto overlap = m_ball.rect().intersected(brick.rect); + auto overlap = new_ball.rect().intersected(brick.rect); if (overlap.width() < overlap.height()) { new_ball.x = m_ball.x; new_ball.vx *= -1;