; The following code which is an example of circular collision detection.
; In this case you have an imaginary 'bounding circle' around each object
; instead of a 'bounding rectangle'. Very handy for more circular objects
; such as asteroids for example. - Alex H.
; Some extra commenting by man@sci.fi
; Note! This is not a complete working code, just an example.
; Required variables :
OBJ1_RADIUS equ ?? ; Radius of bounding circle for object 1
OBJ2_RADIUS equ ?? ; Radius of bounding circle for object 2
obj1_y equ ?? ; Object 1 Y-coordinate
obj1_x equ ?? ; Object 1 X-coordinate
obj2_y equ ?? ; Object 2 Y-coordinate
obj2_x equ ?? ; Object 2 X-coordinate
cc_detect
lda obj1_y ; Calculate the y-difference
suba obj2_y ; between object 1 and object 2.
bpl ccd1 ; Branch if positive,
nega ; if not, lose the sign.
ccd1
tfr a,b ; tfr = transfer register to register
mul ; Square it.
tfr d,x ; Store result in x register.
lda obj1_x ; Calculate the x-difference
suba obj2_x ; Between object 1 and object 2.
bpl ccd2 ; Branch if positive,
nega ; if not, lose the sign.
ccd2
tfr a,b ; tfr = transfer register to register
mul ; Square it
leax d,x ; Add result to x register
cmpx #(OBJ1_RADIUS*OBJ1_RADIUS)+(OBJ2_RADIUS*OBJ2_RADIUS)
ble collided ; If they collide, jump to collided
rts ; Otherwise return to main program