So for this one part of my collision detection routine, I am essentially trying to find out where the point of contact will be on the 8x8 px grid, and then compare it to bits 7-4 of the tile byte, which represents a 16x16px area (each bit corresponding to a 'quadrant'). Seems pretty logical.
The method was to get the tile info on the 16x16px grid (working fine) and then load the newPosition data on a 32x32px grid and determine whether the position falls on an even numbered tile or odd numbered tile on that grid, which will determine whether to look at bytes 7 and 6 or 5 and 4 for horizontal collision data.
So I do this:
LDA newPositionX ; x position of player + playerSpeed...the new potential position
ASL A ; divide by 32 to get spot on the 8px grid
ASL A
ASL A
ASL A
ASL A
STA tileCollsionX ; store it into this variable
........
LDA tileCollisionX ; load the variable
AND #%00000001 ; 'zero' all the bits except the last one
;logically, a zero and one AND witha resulting zero, so
;if the last bit is zero, this will return zero...if it's one, this will return one.
BEQ itIsEven ; if the last bit is zero, that means it must be aligned on an even tile. If a 1, an odd tile.
;;do whatever if it is odd.
itIsEven:
;;do whatever if it is even.
...however, this ALWAYS seems to return even. Anyone see a fundamental problem with my understanding here?
EDIT: Wow....nevermind. All I needed to do was 'write it out' to figure out that should be LSR and not ASL. *smacks forehead*
The method was to get the tile info on the 16x16px grid (working fine) and then load the newPosition data on a 32x32px grid and determine whether the position falls on an even numbered tile or odd numbered tile on that grid, which will determine whether to look at bytes 7 and 6 or 5 and 4 for horizontal collision data.
So I do this:
Code:
LDA newPositionX ; x position of player + playerSpeed...the new potential position
ASL A ; divide by 32 to get spot on the 8px grid
ASL A
ASL A
ASL A
ASL A
STA tileCollsionX ; store it into this variable
........
LDA tileCollisionX ; load the variable
AND #%00000001 ; 'zero' all the bits except the last one
;logically, a zero and one AND witha resulting zero, so
;if the last bit is zero, this will return zero...if it's one, this will return one.
BEQ itIsEven ; if the last bit is zero, that means it must be aligned on an even tile. If a 1, an odd tile.
;;do whatever if it is odd.
itIsEven:
;;do whatever if it is even.
...however, this ALWAYS seems to return even. Anyone see a fundamental problem with my understanding here?
EDIT: Wow....nevermind. All I needed to do was 'write it out' to figure out that should be LSR and not ASL. *smacks forehead*