JyCet
Member
Hi all,
I've a big pb to make a good (see perfect) collision motor for a breakout game.
A ball have a variable speed and a variable angle, does someone have already study a good collision methode for a breakout game ?
Here a sample of my bad collision code <_<
Thk in advance
I've a big pb to make a good (see perfect) collision motor for a breakout game.
A ball have a variable speed and a variable angle, does someone have already study a good collision methode for a breakout game ?
Here a sample of my bad collision code <_<
Code:
void collision2()
{
for (i=0;i<nb_brk;++i)
if (brique.etat[i])
{
if ((balle.x>brique.x[i]-4)&&(balle.x<brique.x[i]+16)&&(balle.y>brique.y[i]-4)&&(balle.y<brique.y[i]+8))
{
if (balle.old_y>balle.y) // balle monte
//for (k=balle.old_y;k<balle.y;--k)
{
if (balle.old_x>balle.x) // gauche
{
if ((balle.y>brique.y[i])&&(balle.y<brique.y[i]+8)) //touche en bas
{
balle.signe_y = 1;
balle.y = k;
flag_collision=1;
}
if ((balle.x>brique.x[i])&&(balle.x<brique.x[i]+16)) // touche a droite
{
balle.signe_x = 1;
balle.x=l;
flag_collision=2;
}
brique.etat[i]=0;
//break;
}
else if (balle.old_x<balle.x) // droite
{
if ((balle.y>brique.y[i])&&(balle.y<brique.y[i]+8)) //touche en bas
{
balle.signe_y = 1;
balle.y = k;
flag_collision=3;
}
if ((balle.x>brique.x[i]-4)&&(balle.x<brique.x[i]+12)) // touche a gauche
{
balle.signe_x = -1;
balle.x=l;
flag_collision=4;
}
brique.etat[i]=0;
}
}
else if (balle.old_y<balle.y) // balledescend
{
if (balle.old_x>balle.x) // gauche
{
if (balle.y==brique.y[i]) //touche en haut
{
balle.signe_y = -1;
balle.y = k;
flag_collision=5;
}
if (balle.y==brique.x[i]+16) // touche a droite
{
balle.signe_x = 1;
balle.x=l;
flag_collision=6;
}
brique.etat[i]=0;
}
else if (balle.old_x<balle.x) // droite
{
if (balle.y==brique.y[i]) //touche en haut
{
balle.signe_y = -1;
balle.y = k;
flag_collision=7;
}
if (balle.x==brique.x[i]) // touche a gauche
{
balle.signe_x = 1;
balle.x=l;
flag_collision=8;
}
brique.etat[i]=0;
}
}
}
}
}
Thk in advance