I've been thinking about improving my code for 'what to do if collision'.
I've been doing something like...
collision left, add 8, and $f0
collision right, and $f0
(plus or minus an adjustment).
ie, aligning to the metatile.
SMB1, just does a-
collision and facing right (-1 x)
collision and facing left (+1 x)
and if you manage to face the wrong direction, you pass through the wall (well known glitch).
So I looked at a few more games. This seems to be a better approach...
Ducktales...
collision right
LDA $0720,X @ $0720 = #$77 ;x position
CLC
ADC $D433,Y @ $D434 = #$0A ;right side offset
STA $0006 = #$81
...
LDA $0006 = #$81
AND #$0F
STA $0006 = #$01
LDA $0720,X @ $0720 = #$77
SEC
SBC $0006 = #$01
STA $0720,X @ $0720 = #$76 ;new x position
collision left
LDA $0720,X @ $0720 = #$28 ;x position
CLC
ADC $D433,Y @ $D436 = #$F6 ;left side offset
STA $0006 = #$1E
...
LDA $0006 = #$1E
AND #$0F
EOR #$0F
SEC
ADC $0720,X @ $0720 = #$28
STA $0720,X @ $0720 = #$2A ;new x position
This seems a bit complicated to me.
What do think is a good method? Is there any other approaches to this?
I've been doing something like...
collision left, add 8, and $f0
collision right, and $f0
(plus or minus an adjustment).
ie, aligning to the metatile.
SMB1, just does a-
collision and facing right (-1 x)
collision and facing left (+1 x)
and if you manage to face the wrong direction, you pass through the wall (well known glitch).
So I looked at a few more games. This seems to be a better approach...
Ducktales...
collision right
LDA $0720,X @ $0720 = #$77 ;x position
CLC
ADC $D433,Y @ $D434 = #$0A ;right side offset
STA $0006 = #$81
...
LDA $0006 = #$81
AND #$0F
STA $0006 = #$01
LDA $0720,X @ $0720 = #$77
SEC
SBC $0006 = #$01
STA $0720,X @ $0720 = #$76 ;new x position
collision left
LDA $0720,X @ $0720 = #$28 ;x position
CLC
ADC $D433,Y @ $D436 = #$F6 ;left side offset
STA $0006 = #$1E
...
LDA $0006 = #$1E
AND #$0F
EOR #$0F
SEC
ADC $0720,X @ $0720 = #$28
STA $0720,X @ $0720 = #$2A ;new x position
This seems a bit complicated to me.
What do think is a good method? Is there any other approaches to this?