// Header File // Created 10/12/2003; 16:30:49 //Algorithmes de collisions //Test de collision (type collision avec billes) short Test_Collide_0 (short x0, short y0, short x1, short y1, unsigned char w0, unsigned char h0, unsigned char w1, unsigned char h1) { short distx=abs ((x0+w0/2)-(x1+w1/2)); short disty=abs ((y0+h0/2)-(y1+h1/2)); if ((distx<(w0/2+w1/2)) && (disty<(h0/2+h1/2))) { distx=((w0/2)+(w1/2))-distx; disty=((h0/2)+(h1/2))-disty; if (distx>disty) { return disty; //if (disty>0) return disty++; //else return disty--; } else { return distx; //if (distx>0) return distx++; //return distx--; } } return 0; } /*unsigned char GetDirCollide_0 (short x0, short y0, short x1, short y1, unsigned char w0, unsigned char h0, unsigned char w1, unsigned char h1) { short distx=abs ((x0+w0/2)-(x1+w1/2)); short disty=abs ((y0+h0/2)-(y1+h1/2)); if ((distx<(w0/2+w1/2)) && (disty<(h0/2+h1/2))) { distx=((w0/2)+(w1/2))-distx; disty=((h0/2)+(h1/2))-disty; if (distx>disty) return 2; //y else return 1; //x } return 0; }*/ //Collision entre rectangles. short TestCollideSquare (short x0, short y0, short x1, short y1, unsigned char w0, unsigned char h0, unsigned char w1, unsigned char h1) { short distx0,distx1; short disty0,disty1; //Si pas collision if (((y1+h1)(y0+h0)) || ((x1+w1)(x0+w0))) return 0; //Détermine la plus petite distance à parcourir pour éviter collision disty0=(y1+h1)-y0+1; disty1=(y0+h0)-y1+1; distx0=(x1+w1)-x0+1; distx1=(x0+w0)-x1+1; if (distx1disty0) distx0=disty0; if (distx0) return distx0; else return 1; } //Direction de la collision unsigned char GetDirCollideSquare (short x0, short y0, short x1, short y1, unsigned char w0, unsigned char h0, unsigned char w1, unsigned char h1) { //Si pas collision if (((y1+h1)(y0+h0))) return 2; //y if (((x1+w1)(x0+w0))) return 1; //x return 0; } //Direction de la collision unsigned char GetDirCollideSquare2 (short x0, short y0, short x1, short y1, unsigned char w0, unsigned char h0, unsigned char w1, unsigned char h1) { unsigned char collide=0; //Si pas collision if ((y1+h1)(y0+(h0/2))) collide|=2; //y Bas if ((x1+w1)(x0+(w0/2))) collide|=8; //x Droit return collide; } /*#define SWAPDATA(a,b) asm volatile ("exg %0,%1" : "=d" (a), "=d" (b) : "0" (a), "1" (b) : "cc") //Teste collision entre sprite de 8 pixels BOOL TestCollideSprite8 (short x0, short y0, short x1, short y1, unsigned char h, unsigned char *sprite0, unsigned char *sprite1) { short dx,dy,i; //Sprite 0 à droite de sprite 1 if (x0=8) return 0; //Aucune collision if (y0=16) return 0; //Aucune collision if (y0=32) return 0; //Aucune collision if (y0>dx) & (((unsigned long)*sprite0))) return 1; } return 0; }*/