;-----------------------------------------------------------; ; ; ; Invaded ; ; Version 1.0 ; ; Collision Detection Routine ; ; ; ;-----------------------------------------------------------; ;------------------------------------------------ ; checkCollision - Check for collisions between two objects ; ; Author: Patrick Davidson (http://pad.calc.org) ; Modified slightly by James Vernon ; Input: (collideObject1) = Object 1 [x, width, y, height] ; (collideObject2) = Object 2 [x, width, y, height] ; Output: CA = 1 if they are colliding ;------------------------------------------------ checkCollision: ld hl,collideObject1 ld de,(collideObject2) ld a,(hl) sub e jr c,checkCollision1 cp d ret nc inc hl jr checkCollision2 checkCollision1: neg inc hl cp (hl) ret nc checkCollision2: ld de,(collideObject2+2) inc hl ld a,(hl) sub e jr c,checkCollision3 cp d ret checkCollision3: neg inc hl cp (hl) ret .end