résolution pixel vert qui apparait de nulle part

This commit is contained in:
Vincent TEISSIER 2023-12-12 12:12:22 +01:00
parent 224497863a
commit 1673dc4f5f
2 changed files with 12 additions and 3 deletions

@ -80,14 +80,13 @@ void DeplacementSerpent(int direction ,int *serpent, int longueur)
int tempX = serpent[0]; int tempX = serpent[0];
int tempY = serpent[1]; int tempY = serpent[1];
int i; int i;
int compteur;
couleur g; couleur g;
couleur j; couleur j;
ChoisirEcran(2); ChoisirEcran(2);
j=CouleurParNom("yellow"); j=CouleurParNom("yellow");
g=CouleurParNom("lightgreen"); g=CouleurParNom("lightgreen");
ChoisirCouleurDessin(g);
RemplirRectangle(serpent[longueur-2],serpent[longueur-1],T_PIXEL,T_PIXEL);
for (i = 2; i < longueur; i += 2) { for (i = 2; i < longueur; i += 2) {
int tempX2 = serpent[i]; int tempX2 = serpent[i];
@ -99,6 +98,16 @@ void DeplacementSerpent(int direction ,int *serpent, int longueur)
tempX = tempX2; tempX = tempX2;
tempY = tempY2; tempY = tempY2;
} }
for(i=0;i< longueur; i++)
{
if(serpent[i] != NULL)
{
compteur++;
}
}
ChoisirCouleurDessin(g);
RemplirRectangle(serpent[compteur-2],serpent[compteur-1],T_PIXEL,T_PIXEL);
ChoisirCouleurDessin(j); ChoisirCouleurDessin(j);
if(direction == 0) /* Direction vers la gauche */ if(direction == 0) /* Direction vers la gauche */

2
main.c

@ -185,7 +185,7 @@ int main()
DeplacementSerpent(direction,serpent,longueur_serpent); DeplacementSerpent(direction,serpent,longueur_serpent);
if(MangerPastille(serpent,pastilles,&score) == 1) if(MangerPastille(serpent,pastilles,&score) == 1)
{ {
longueur_serpent+=2; longueur_serpent+=4;
serpent = (int*) realloc(serpent,longueur_serpent * sizeof(int)); serpent = (int*) realloc(serpent,longueur_serpent * sizeof(int));
} }
} }