I'm working on a fairly complex sprite that I want to have interaction with a lot of the vanilla sprites. I wrote a loop that is run every frame that checks for contact between my sprite (sprite A) and all other sprite's. I then index with the other sprite's number to see what interaction routine will be called (this is not as absurdly large a task as it sounds because a lot of sprites will use a default interaction).
At the end of the routine however, $00 is not equal to INTERACTION_TABLE indexed by sprite B's sprite number (at least it's not equal to what Lunar Magic says the sprite number is). I don't know if I've been at this thing for too damn long or I'm just really stupid.
I mean, sprite number does mean what sprite it is, right? For example a bullet bill has $9E,x = #$1C.
This is my code:
TXY ;Store X to Y
PHX ;Push X
LDA #$FF ;\This starts the loop off at X=#$FF
STA $1695 ;/
LOOP LDX $1695
LOOPX INX ;Increment X (the first time this happens X is set to zero)
CMP #$0C ; |Terminate loop if it has been run 12 times this frame
BEQ RETURN_INT ;/
CMP $15E9 ; |Loop if sprite is trying to compare clipping values with itself
BEQ LOOPX ;/
JSL $03B6E5 ;Get sprite B's clipping values (sprite B is whichever one being checked)
STX $1695 ;Store X value for sprite B
TYX ;Restore X from Y
JSL $03B69F ;Get sprite A's clipping values
JSL $03B72B ;Check for contact (if they touch the carry flag will be set)
BCC LOOP ;Loop if carry is clear
LDX $1695 ;Load sprite B's X value (sprite B is now confirmed to touch sprite A)
LDA 9E,x ;Load sprite B's sprite number
TAX ;Store sprite B's sprite number to X
LDA INTERACTION_TABLE,x ;Load specific interaction value indexed by sprite number
STA $00 ;Store to scratch RAM
The table is 256 bytes long to work with any possible sprite number. I will shrink it when I find out how many sprite numbers are actually used.
Edit: I had simply been at it for too long. I missed the '$' in LDA $E9,x. Derp.
Sorry for wall of text.
We’re looking for level designers to work on Extra Mario World