I stumbled upon this problem while i was making my 2D freelance game ( WIP ). the problem was that when i had bullets that moved very fast, they sometimes just flew over the enemy instead of impacting.
At this time i was using the basic pythagoras theorem to get the distance between target and bullet and check if that was lower than the targets radius.
the new method is more complex, it checks if the bullet and target have been within range during the last "frame" using simple maths. ( it doesnt iterate anything )
the result is that you can have bullets of any velocity!
possible uses :
-to check bullet collision ( DUH )
-if you set the bullet velocity to fast enough this can be used as a 2D raycast

-it can easily be modified to get the coordinates.
and the code :
where x1#,y1# are the coordinates of either the bullet or the enemy
xv1# and yv1# the x and y velocities of the bullet or the enemy
(remember that x1#,y1#,xv1# and yv1# must be of the same entity ! )
and ofcourse x2#,y2#... are the same but for the other one
r# is the radius of the target
( if your bullet also has a radius then add that and the targets radius together here )
function advbullethit(x1#,y1#,xv1#,yv1#,x2#,y2#,xv2#,yv2#,r#)
a# = x1#-x2# : b# = y1#-y2# : c# = xv1#-yv1# : d# = yv1#-yv2#
e# = a#^2 : f# = b#^2 : g# = c#^2 : h# = d#^2 : r# = r#^2
cd# = (g#+h#)*r# : ad# = e#*h# : abcd# = 2*a#*b#*c#*d# : bc# = f#*g#
ac# = a#*c# : bd# = b#*d# : bot# = g#+h#
sq# = cd#-ad#+abcd#-bc# : ex1# = ac#+bd# : ex2 = -ac#-bd#
if sq# > 0 then sq# = sqrt(sq#)
if bot# > 0 then k1# = (sq#+ex1#)/bot# : k2# = (-sq#-ex2#)/bot#
if k1# < 0 then k1# = 10000000
if k2# < 0 then k2# = 10000000
k# = min(k1#,k2#)
if k# <= 1 then yes = 1
endfunction yes
this function will return a 1 if it was a hit and 0 if it wasnt
use it like this
if advbullethit(enemyx#,enemyy#,enemyxv#,enemyyv#,bulletx#,bullety#,bulletxv#,bulletyv#,enemyradius#+5) = 1 then dec enemyhp#,bulletdamage#
how to get x and y velocity ?
very easy with vectors, otherwise like this :
ox# = x# : oy# = y#
x# = x#+4 : y# = y#+3 ' player moves 4 along the x and 3 along y
xv# = x#-ox# : yv# = y#-oy#