The most useful post I've found was here https://forums.nesdev.com/viewtopic.php?f=10&t=12995 and I've been trying some of the code examples in it which you'll see below.
Right now I have a 32x30 byte array for my background that I load through 5 loops via:
Code: Select all
LoadBackground:
LDA $2002
LDA #$20
STA $2006
LDA #$00
STA $2006
LDY #$00
LDX #$00
LoadBackgroundLoop1:
LDA background_lvl_1_1, y
STA $2007
INY
INX
CPX #$00
BNE LoadBackgroundLoop1
;;done 4 more times
I'm going off of tokumaru's code example in the above post and I have come to this:
Code: Select all
LDA #$00
STA L
LDA PLAYER_POS_Y ;oam $0200
AND #%11111000 ;why this?
ASL
ROL L
ASL
ROL L
ADC #<background_lvl_1_1
STA H
LDA L
ADC #>background_lvl_1_1
STA L
LDA PLAYER_POS_X ;oam $0203
LSR
LSR
LSR
TAY
LDA (H), Y
CMP #$04
BCC No_Collision
Collision:
LDA #$02
STA $0202
JMP CollisionDone
No_Collision:
LDA #$00
STA $0202
CollisionDone:
H = $20
L = H+1
Right now I have my sprite player just turning a different color to show me if the collision is working, but I want to register a collision when the player hits a tree, which is #$04 in background_lvl_1_1 while the blank pathways are #$00.
I can see in the debugger that the final value after LDA (H), y is always #$04 no matter where the character is on screen and is always from a single location - so it isn't updating the location of every time I move the player sprite. I currently have this above collisions routine in my "forever" loop as well.
Is that because it is only reading from "background_lvl_1_1" and not going through the other sets of background data I have? Do I have to run this same routine with all my background data? (background_lvl_1_2, background_lvl_1_3, etc?) It seems so close, what am I missing? I'm not using meta sprites either, if that has anything to do with this...
(Sorry for my noobness, and thanks in advance)