Hi all,
I'm working on the collision detection for my PONG style game and I was hoping to gain some clarification so I can better understand compare statements, as well as to refine the collision detection. I have the collision detection semi-working but its a bit glitchy. I don't fully understand the branch statements so I was hoping you could clear that up for me.
The PONG paddle in this case is actually composed of 16 tiles. 4x4 tiles to be exact. My code is for collision detection is this:
The code basically works, however there are some issues with it.
1. I understand that BCS looks to the status register of the carry flag to make its branch decision, however in simple terms, is it basically used as a "greater than" function?
2. Same for BCC. Is this basically used for a less than function?
3. In my first piece of comparison code, I'm using a BCS to compare the horizontal position. This seems to work in the game, but logically doesn't make sense to me. It would seem that the code should BNE, meaning that the ball horizontal position is not the same as the paddle position and as such should then jump to paddle collision done, allowing the ball to pass by the paddle. This doesn't work though. BCS seems to work, but it logically doesn't make sense to me.
4. For the most part, my paddle collision works, but many times the ball passes right behind the paddle and then immediately bounces back from behind the paddle instead of in front of it.
Thanks again. The journey of learning to code for NES continues on
I'm working on the collision detection for my PONG style game and I was hoping to gain some clarification so I can better understand compare statements, as well as to refine the collision detection. I have the collision detection semi-working but its a bit glitchy. I don't fully understand the branch statements so I was hoping you could clear that up for me.
The PONG paddle in this case is actually composed of 16 tiles. 4x4 tiles to be exact. My code is for collision detection is this:
Code:
CheckPaddleCollision:
;;Check Horizontal Position of Ball
LDA ballx ;Load current horizontal position of ball
CMP $0243 ;Compare to horizontal position of paddle
BCS CheckPaddleCollisionDone ;if ball x position is greater than the x position of the far right column of tiles which the sprite is composed branch to CheckPaddleCollisionDone. Otherwise move on to vertical
;;Check Vertical Position of Ball
LDA bally ;Load current vertical position of ball
CMP $0204 ;Compare to vertical position of the top tile of the sprite. If ball y position is less than branch to CheckPaddle Collision Done. Otherwise Move on.
BCC CheckPaddleCollisionDone
;;Vertical Position Check Continued. Check Bottom Position of Ball
LDA bally ;;Load Current Vertical Position of ball
CMP $0210 ;; Compare to vertical position of the bottom tile of the sprite. If ball y position is greater than the vertical position of the tile branch to paddle collision done.
BCS CheckPaddleCollisionDone
;Perform Ball Hand Slap Animation By Jumping To The Subroutine That Does This
JSR Dave_Slap
;;bounce, ball now moving right
LDA #$01
STA ballright
LDA #$00
STA ballleft
;;Check Horizontal Position of Ball
LDA ballx ;Load current horizontal position of ball
CMP $0243 ;Compare to horizontal position of paddle
BCS CheckPaddleCollisionDone ;if ball x position is greater than the x position of the far right column of tiles which the sprite is composed branch to CheckPaddleCollisionDone. Otherwise move on to vertical
;;Check Vertical Position of Ball
LDA bally ;Load current vertical position of ball
CMP $0204 ;Compare to vertical position of the top tile of the sprite. If ball y position is less than branch to CheckPaddle Collision Done. Otherwise Move on.
BCC CheckPaddleCollisionDone
;;Vertical Position Check Continued. Check Bottom Position of Ball
LDA bally ;;Load Current Vertical Position of ball
CMP $0210 ;; Compare to vertical position of the bottom tile of the sprite. If ball y position is greater than the vertical position of the tile branch to paddle collision done.
BCS CheckPaddleCollisionDone
;Perform Ball Hand Slap Animation By Jumping To The Subroutine That Does This
JSR Dave_Slap
;;bounce, ball now moving right
LDA #$01
STA ballright
LDA #$00
STA ballleft
The code basically works, however there are some issues with it.
1. I understand that BCS looks to the status register of the carry flag to make its branch decision, however in simple terms, is it basically used as a "greater than" function?
2. Same for BCC. Is this basically used for a less than function?
3. In my first piece of comparison code, I'm using a BCS to compare the horizontal position. This seems to work in the game, but logically doesn't make sense to me. It would seem that the code should BNE, meaning that the ball horizontal position is not the same as the paddle position and as such should then jump to paddle collision done, allowing the ball to pass by the paddle. This doesn't work though. BCS seems to work, but it logically doesn't make sense to me.
4. For the most part, my paddle collision works, but many times the ball passes right behind the paddle and then immediately bounces back from behind the paddle instead of in front of it.
Thanks again. The journey of learning to code for NES continues on