Collision Detection Functions and Macros


BOUNDS_COLLIDE(x0,y0,x1,y1,w,h)

Checks if two rectangle areas of width w and height h starting at (x0,y0) and (x1,y1) overlaps. Returns 0 if areas won't overlap.

BOUNDS_COLLIDE8(x0,y0,x1,y1)

Checks if two square areas of width 8 and height 8 starting at (x0,y0) and (x1,y1) overlaps. Returns 0 if areas won't overlap.

BOUNDS_COLLIDE16(x0,y0,x1,y1)

Checks if two square areas of width 16 and height 16 starting at (x0,y0) and (x1,y1) overlaps. Returns 0 if areas won't overlap.

BOUNDS_COLLIDE32(x0,y0,x1,y1)

Checks if two square areas of width 32 and height 32 starting at (x0,y0) and (x1,y1) overlaps. Returns 0 if areas won't overlap.

short TestCollide8(short x0,short y0,short x1,short y1,short h,unsigned char* data0, unsigned char* data1);

short TestCollide8_R(register short x0 asm("%d0"),register short y0 asm("%d1"),register short x1 asm("%d2"),register short y1 asm("%d3"),short height,register unsigned char* data0 asm("%a0"),register unsigned char* data1 asm("%a1")) __attribute__((__stkparm__));

Checks if the content of two sprites of width 8 and height h starting at (x0,y0) and (x1,y1) overlaps. Returns 0 if sprites won't overlap. In difference to the bounds checking macros these functions tests the content of two sprites by shifting the content if necessary and "AND"-ing the data together. If a set pixel overlaps (i.e. is set in both sprites) a collision is detected. This way you can test irregulary shaped sprites for collision and not only rectangular ones. data0 and data1 are pointers to the content of the two sprites. For grayscale sprites it is a good idea to use a special type of mask data for data0 and data1 where every pixel is set which should be involved in testing. A simple way to generate such a mask is to OR the data of the dark plane and the light plane together into one plane. If you use such a mask you'll need to call TestCollide8 only once.

short TestCollide16(short x0,short y0,short x1,short y1,short h,unsigned short* data0, unsigned short* data1);

short TestCollide16_R(register short x0 asm("%d0"),register short y0 asm("%d1"),register short x1 asm("%d2"),register short y1 asm("%d3"),short height,register unsigned short* data0 asm("%a0"),register unsigned short* data1 asm("%a1")) __attribute__((__stkparm__));

Checks if the content of two sprites of width 16 and height h starting at (x0,y0) and (x1,y1) overlaps. Returns 0 if sprites won't overlap. In difference to the bounds checking macros these functions tests the content of two sprites by shifting the content if necessary and "AND"-ing the data together. If a set pixel overlaps (i.e. is set in both sprites) a collision is detected. This way you can test irregulary shaped sprites for collision and not only rectangular ones. data0 and data1 are pointers to the content of the two sprites. For grayscale sprites it is a good idea to use a special type of mask data for data0 and data1 where every pixel is set which should be involved in testing. A simple way to generate such a mask is to OR the data of the dark plane and the light plane together into one plane. If you use such a mask you'll need to call TestCollide16 only once.