Hi folks! I'm in the process of writing my own homebrew game and implementing collision detection has been a troublesome task, as I am stuck at an error that seems to have no explanation and figured this would be the right forum to ask.
The data I am working with is an entire uncompressed screen (well, 2 of them but at this moment I am only concerned about working with one.)
This is the code I am working with.
checkCollisionRight:
LDA #$20 ;; Hi byte since nametable starts at $2000
STA collisionHi
LDA HeroY ;; Takes Hero Y coordinate, divides by 8
LSR A
LSR A
LSR A
STA collisionLo
LDX #$00
shiftLoop:
LDA collisionLo
CLC
ASL A
STA collisionLo
LDA collisionHi
ADC #$00
STA collisionHi
INX
CPX #$05 ;; This run five times since it must be multiplied by 32
BNE shiftLoop
endCollision:
RTS
All this is trying to do at the moment is returning the current line that the hero is walking on, not the exact tile. It does fine for the first half of the screen, from $2000-21FF, but for some reason, when the hero is beyond tiles $2200, the high byte does not increment but rather loops from $2100 all over again. Only once you reach the bottom quarter of the screen does it increase to $2200, where it should actually be at $2300.
The data I am working with is an entire uncompressed screen (well, 2 of them but at this moment I am only concerned about working with one.)
This is the code I am working with.
checkCollisionRight:
LDA #$20 ;; Hi byte since nametable starts at $2000
STA collisionHi
LDA HeroY ;; Takes Hero Y coordinate, divides by 8
LSR A
LSR A
LSR A
STA collisionLo
LDX #$00
shiftLoop:
LDA collisionLo
CLC
ASL A
STA collisionLo
LDA collisionHi
ADC #$00
STA collisionHi
INX
CPX #$05 ;; This run five times since it must be multiplied by 32
BNE shiftLoop
endCollision:
RTS
All this is trying to do at the moment is returning the current line that the hero is walking on, not the exact tile. It does fine for the first half of the screen, from $2000-21FF, but for some reason, when the hero is beyond tiles $2200, the high byte does not increment but rather loops from $2100 all over again. Only once you reach the bottom quarter of the screen does it increase to $2200, where it should actually be at $2300.