**************************************************************************** **************************************************************************** ** ** Platinum (Collision detection) ** ** This software is in the public domain. There is no warranty. ** ** by Patrick Davidson (pad@calc.org, http://pad.calc.org/) ** ** Last updated July 13, 2001 ** **************************************************************************** **************************************************************************** ******************************************** TEST FOR COLLISIONS * * This routine tests two objects for collisions. It returns with the zero * flag set (equal) if there is no collision, and the zero flag clear * (not equal) if there is a collision. It first checks whether the * rectangular boundaries of the objects overlap. If they do, it then tests * whether the images (dark planes only) overlap. * * This routine is guaranteed to preserve A1, A5, A6 and D4-D7. All other * registers may be changed. * * Parameters: * * A3 -> Bullet, enemy, or enemy bullet structure of one object * A4 -> Bullet, enemy, or enemy bullet structure of the other * ******** no_collision: moveq #0,d0 rts Test_Collision: move.w e_y(a4),d0 ; Test Y-coord overlap blt no_collision add.w e_h(a4),d0 sub.w b_y(a3),d0 ble.s no_collision sub.w e_h(a4),d0 sub.w b_h(a3),d0 bge.s no_collision move.w e_x(a4),d0 ; Test X-coord overlap add.w e_w(a4),d0 sub.w b_x(a3),d0 ble.s no_collision sub.w e_w(a4),d0 sub.w b_w(a3),d0 bge.s no_collision \test: nop nop move.w e_y(a4),d0 sub.w e_y(a3),d0 ; test A4->e_y - A3->e_y bge.s \a3top ; branch if A3 is on top exg a3,a4 neg.w d0 \a3top: lea image_table(pc),a2 move.w e_image(a4),d1 lea 2(a2,d1.w),a0 ; A0 -> image of A4 sprite add.w d0,d0 add.w d0,d0 add.w e_image(a3),d0 lea 2(a2,d0.w),a2 ; A2 -> image of A3 sprite move.w e_y(a3),d0 add.w e_h(a3),d0 sub.w e_y(a4),d0 subq.w #1,d0 ; D0 = number of lines to check - 1 move.w e_x(a4),d1 sub.w e_x(a3),d1 ; D1 = amount to shift A3 enemy left blt.s \a3right beq.s \samey \ll: move.l (a2)+,d2 move.l (a0)+,d3 lsl.l d1,d2 and.l d2,d3 bne.s \rts dbra d0,\ll \rts: rts \a3right: neg.w d1 \rl: move.l (a2)+,d2 move.l (a0)+,d3 lsr.l d1,d2 and.l d2,d3 bne.s \rts dbra d0,\rl rts \samey: move.l (a2)+,d2 and.l (a0)+,d2 bne.s \rts dbra d0,\samey rts