Typo in Part II. 18. Collision
Closed this issue · 2 comments
LargeBee commented
Regarding the Paddle Bounce code
; First, check if the ball is low enough to bounce off the paddle.
ld a, [_OAMRAM]
ld b, a
ld a, [_OAMRAM + 4]
cp a, b
jp nz, PaddleBounceDone ; If the ball isn't at the same Y position as the paddle, it can't bounce.
; Now let's compare the X positions of the objects to see if they're touching.
ld a, [_OAMRAM + 5] ; Ball's X position.
ld b, a
ld a, [_OAMRAM + 1] ; Paddle's X position.
sub a, 8
cp a, b
jp c, PaddleBounceDone
add a, 8 + 16 ; 8 to undo, 16 as the width.
cp a, b
jp nc, PaddleBounceDone
ld a, -1
ld [wBallMomentumY], a
PaddleBounceDone:
should the X position checking instead be
ld a, [_OAMRAM + 5] ; Ball's X position.
ld b, a
ld a, [_OAMRAM + 1] ; Paddle's X position.
sub a, 8
cp a, b
jp nc, PaddleBounceDone
add a, 8 + 16 ; 8 to undo, 16 as the width.
cp a, b
jp c, PaddleBounceDone
the conditionals for both jump commands should be swapped I believe. This allows the program to work for me where the tutorial code didn't. It makes more sense as the first jump should occur if the ball's X position is less than the paddle's X position but with jp c
it jumps out of the bounce procedure whenever the Ball's X is greater than the Paddle's X
evie-calico commented
This is already resolved by #59