Code: Select all
pw = width of player's hitbox
ow = width of object's hitbox
dist_x = ((pw/2) + (ow/2))
*the camera relative coordinate has to be at the center of the object for the hit to occur equally on both sides
Code: Select all
Test_Object_Collision:
LDA player_x_rel ; player x position relative camera
SEC
SBC obj_00_x_rel,X ; current object's x position relative camera
BCS ResultPlusX ; X reg has current object slot
EOR #$FF ; reverse sign if result was negative
CLC
ADC #$01
ResultPlusX:
CMP Hit_Distance_X,Y ; compare result to required distance for collision
BCS NoCollision ; Y reg has the index to the desired hit distance
LDA player_y_rel ; player y position relative camera
SEC
SBC obj_00_y_rel,X ; current object's y position relative camera
BCS ResultPlusY ; X reg has current object slot
EOR #$FF ; reverse sign if result was negative
CLC
ADC #$01
ResultPlusY:
CMP Hit_Distance_Y,Y ; compare result to required distance for collision
; Y reg has the index to the desired hit distance
NoCollision:
RTS ; ------------------------------------------------