SGE Documentation - Collision detection

# Basic collision detection

- sge_make_cmap
- sge_bbcheck
- sge_bbcheck_shape
- sge_cmcheck
- sge_get_cx/y
- sge_unset_cdata
- sge_set_cdata
- sge_destroy_cmap

sge_cdata *sge_make_cmap(SDL_Surface *img)
Creates a new collision map. Use SDL_SetColorKey() before calling this function. Every non-transparent pixel is set to solid in the collision map. The collision map is bit encoded in a Uint8 array. Returns the collision map or NULL on error.
int sge_bbcheck(sge_cdata *cd1,Sint16 x1,Sint16 y1, sge_cdata *cd2,Sint16 x2,Sint16 y2)
int _sge_bbcheck(Sint16 x1,Sint16 y1,Sint16 w1,Sint16 h1, Sint16 x2,Sint16 y2,Sint16 w2,Sint16 h2)
Checks if two rectangles (the bounding boxes) overlap. Returns 1 if so or else 0.
int sge_bbcheck_shape(sge_shape *shape1, sge_shape *shape2)
Checks if two shapes (the bounding boxes) overlap. Returns 1 if so or else 0.
int sge_cmcheck(sge_cdata *cd1,Sint16 x1,Sint16 y1, sge_cdata *cd2,Sint16 x2,Sint16 y2)
int _sge_cmcheck(sge_cdata *cd1,Sint16 x1,Sint16 y1, sge_cdata *cd2,Sint16 x2,Sint16 y2);
Does pixel perfect collision detection. The (x1,y1) and (x2,y2) coords are the positions of the upper left corners of the images. You MUST call sge_bbcheck() before using _sge_cmcheck(), sge_cmcheck() does this automatically. Returns 1 if any solid pixels of the two images overlap or else 0.
Sint16 sge_get_cx(void)
Sint16 sge_get_cy(void)
Returns the position of the last collision found by sge_cmcheck().
void sge_unset_cdata(sge_cdata *cd, Sint16 x, Sint16 y, Sint16 w, Sint16 h)
Clears an area in the collision map from anything solid.
void sge_set_cdata(sge_cdata *cd, Sint16 x, Sint16 y, Sint16 w, Sint16 h)
Makes an area in the collision map solid.
void sge_destroy_cmap(sge_cdata *cd)
Removes collision map from memory.

Copyright © 1999-2003 Anders Lindström
Last updated 030808