Skip to content

Commit ab0e6a1

Browse files
committed
Minor changes
1 parent a52d0fe commit ab0e6a1

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

Chapter01/Game.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,17 @@ void Game::UpdateGame()
152152
mBallPos.y += mBallVel.y * deltaTime;
153153

154154
// Bounce if needed
155-
// Did we intrsect with the paddle?
155+
// Did we intersect with the paddle?
156156
float diff = mPaddlePos.y - mBallPos.y;
157+
// Take absolute value of difference
157158
diff = (diff > 0.0f) ? diff : -diff;
158-
if (mBallPos.x <= 25.0f && mBallPos.x >= 20.0f && diff <= paddleH/2.0f
159-
&& mBallVel.x < 0.0f)
159+
if (
160+
// Our y-difference is small enough
161+
diff <= paddleH / 2.0f &&
162+
// We are in the correct x-position
163+
mBallPos.x <= 25.0f && mBallPos.x >= 20.0f &&
164+
// The ball is moving to the left
165+
mBallVel.x < 0.0f)
160166
{
161167
mBallVel.x *= -1.0f;
162168
}

0 commit comments

Comments
 (0)