Pour les détections de collisions par rectangles en C, c'est très simple. Voilà des macros tirés de
ExtGraph de Thomas Nussbaumer, une librairie graphique pour les calculatrices TI-89/92+/V200:
// macro which returns the absolute value of a given short
#define EXT_SHORTABS(a) ({register short ta=(a); (ta>=0) ? ta : -ta;})
// macro which checks two bounding rectangles starting at (x0/y0) and (x1/y1) for
// collision. w is the width in pixels and h the height of the two bounding rectangles
#define BOUNDS_COLLIDE(x0,y0,x1,y1,w,h) \
((EXT_SHORTABS((x1)-(x0))<(w))&&(EXT_SHORTABS((y1)-(y0))<(h)))
// handy aliases for standard tile sizes (8x8 / 16x16 / 32x32)
#define BOUNDS_COLLIDE8(x0,y0,x1,y1) BOUNDS_COLLIDE(x0,y0,x1,y1,8,8)
#define BOUNDS_COLLIDE16(x0,y0,x1,y1) BOUNDS_COLLIDE(x0,y0,x1,y1,16,16)
#define BOUNDS_COLLIDE32(x0,y0,x1,y1) BOUNDS_COLLIDE(x0,y0,x1,y1,32,32)
Ces macros devraient être compilables sans problème avec n'importe quelle version de
GCC, y compris la version pour GP32. La seule chose qui est demandée (mais pas exigée à ce qu'il me semble) si tu utilises ces macros est un merci à Thomas Nussbaumer avec un lien vers
http://tict.ticalc.org quelque part dans les crédits.
Documentation:
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.