;哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪
;This is the collision detection routine I use in XC-1701.
;It tests wether the shoot at (H,L) collides with the ship at (D,E)
;If so, A holds 1.
;The one-byte variable Width holds the width of the enemy ship
;
;As XC-1701 is my first program for ZShell, this routine is not optimized.
;If you find a way to do this faster, please write me a letter:
; Andreas Ess
; Tufers 156
; A-6811 Goefis
; Austria/Europe
;
;Please give me an appropriate credit if you use this peace of code.
; Thanx, Andreas
;哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪

;-----------------------------------------------------------------------------
;ShootCollision: is there a collision between a shoot with position hl and
;                an enemy ship with position de? if yes -> a = 1
;-----------------------------------------------------------------------------
ShootCollision:
 push bc
 push de
 push hl
 ld  a, h               ;load x-pos into a
 cp  d                  ;is x-pos greater than d and smaller than d+8?
 jr  c, EndCollDet      ;no

 ld  a, (Width)
 ld  b, a
 ld  a, d               ;add width to d
 add a, b
 ld  d, a
 ld  a, h               ;save x-pos again into a
 cp  d                  ;compare it with the incremented d
 jr  nc, EndCollDet

 ;Ok, x is within ship, but what about y?
 ld  a, l               ;load y-pos into a
 cp  e                  ;is y-pos greater then e?
 jr  c, EndCollDet

 ld  a, (Width)
 ld  b, a
 ld  a, e               ;add width to e
 add a, b
 ld  e, a
 ld  a, l               ;save y-pos again into a
 cp  e
 jr  nc, EndCollDet
 ;Collision!
 ld  a, 1
 jr  EndCollDet1
EndCollDet:
 ld   a, 0
EndCollDet1:
 pop  hl
 pop  de
 pop  bc
 ret
