[Original snippet by Wyz]It can be very usefull to shoot'em up programers. This is my proposal:
Considering only starting and final points (shooter and objetive)
; DIRECTION OF A LINEAR TRAJECTORY
; MODULE APROX. TO 1
; POSICION INICIAL: XI,YI
; POSICION FINAL: XF,YF
; INCREMENTOS; INCX,INCY
LD HL,[XI]
EX DE,HL
LD HL,[XF] ;D=YI,E=XI,H=YF,L=XF
LD A,H ;SIGNO Y
SBC D
LD A,0
RLA
LD [SIGN_INCY],A
LD A,L ;SIGNO X
SBC E
LD A,0
RLA
LD [SIGN_INCX],A
SBC HL,DE ;MODULE~1
MODBC0: BIT 7,H ;IF START=FINAL => HANGS
JR NZ,FIN
BIT 7,L
JR NZ,FIN
RLC H
RLC L
JR MODBC0
FIN: LD [INCX],HL
RET
XI: DB 10 ;START POSITION (EXAMPLE)
YI: DB 10
XF: DB 80 ;FINAL POSITION
YF: DB 80
INCX: DB 0 ;INC COORD X
INCY: DB 0 ;INC COORD Y
SIGN_INCX: DB 0 ;SIGNO INCX
SIGN_INCY: DB 0 ;SIGNO INCY
;___________________________________________________
;THEN TO MOVE A BULLET(X,Y) DEFINE
;X AS WORD - HIGH BYTE TO SPRITE COORD X,Y
;Y AS WORD -
;INCX AS BYTE
;INCY AS BYTE
;AND CONSIDER THE SIGN
LD HL,[X]
LD A,[INCX]
LD D,0
LD E,A
LD A,[SIGN_INCX]
AND A
JR NZ,THEN_SUBSTRACT
ADD HL,DE
JR NEXT
THEN_SUBSTRACT: SBC HL,DE
NEXT: LD [X],HL
....