correction segmentation collission

This commit is contained in:
David AKAGUNDUZ 2023-12-17 19:35:53 +01:00
parent dd9d51bb1a
commit c3c14e39c9
6 changed files with 12 additions and 5 deletions

@ -40,20 +40,21 @@ void InitialiserPastilles(PIXELS *pastilles, PIXELS *serpent, int longueur_serpe
}
}
void MourrirSerpent(PIXELS *serpent, int longueur_serpent)
int MourrirSerpent(PIXELS *serpent, int longueur_serpent)
{
int i = 0;
for(i=1;i<longueur_serpent;i++)
{
if(serpent[0].x == serpent[i].x && serpent[0].y == serpent[i].y )
{
FermerGraphique();
return 1;
}
}
if (serpent[0].x<=0 || serpent[0].x>W_GAME || serpent[0].y<=0 || serpent[0].y>H_GAME)
{
FermerGraphique();
return 1;
}
return 0;
}
int MangerPastille(PIXELS *serpent, PIXELS* pastilles,unsigned long *score,int longueur_serpent)

@ -13,7 +13,7 @@ void AfficherTimerEtScore(long unsigned int *score,int minutes,int secondes);
int PastilleSurSerpent(PIXELS pastille, PIXELS *serpent, int longueur_serpent);
void MourrirSerpent(PIXELS *serpent, int longueur_serpent);
int MourrirSerpent(PIXELS *serpent, int longueur_serpent);
#endif

Binary file not shown.

8
main.c

@ -207,7 +207,13 @@ int main()
suivant=Microsecondes()+delta;
AfficherTimerEtScore(&score,minutes,secondes);
direction_davant = direction; /* Check si le serpent à le droit de changer de direction */
MourrirSerpent(serpent,longueur_serpent);
if(MourrirSerpent(serpent,longueur_serpent))
{
FermerGraphique();
free(serpent);
free(pastilles);
return EXIT_FAILURE;
}
DeplacementSerpent(direction,serpent,longueur_serpent);
if(MangerPastille(serpent,pastilles,&score,longueur_serpent) == 1)
{

BIN
main.o

Binary file not shown.

BIN
prog

Binary file not shown.