diff --git a/evenement.c b/evenement.c index 02eaaf6..b0870c5 100644 --- a/evenement.c +++ b/evenement.c @@ -38,7 +38,7 @@ void InitialiserPastilles(PIXELS *pastilles) { } } -void MangerPastille(int *serpent, PIXELS* pastilles, size_t *longueur_serpent, size_t longueur_pastilles) +void MangerPastille(int *serpent, PIXELS* pastilles, size_t *longueur_serpent, size_t longueur_pastilles,unsigned long *score) { couleur r; int i = 0; @@ -54,6 +54,7 @@ void MangerPastille(int *serpent, PIXELS* pastilles, size_t *longueur_serpent, s pastilles[i] = gen_pastille(); RemplirRectangle(pastilles[i].x,pastilles[i].y,T_PIXEL,T_PIXEL); *longueur_serpent+=2;/*augmente la taille du serpent de deux car un pixel =2*/ + *score+=5; printf("%ld",*longueur_serpent); /*voir la taille du serpent*/ } } @@ -61,6 +62,20 @@ void MangerPastille(int *serpent, PIXELS* pastilles, size_t *longueur_serpent, s } +int PastilleSurSerpent(PIXELS pastille, int *serpent, size_t longueur_serpent) +{ + int i; + + for(i=0;i<longueur_serpent;i+=2) + { + if (pastille.x==serpent[i] && pastille.y ==serpent[i+1]) + { + return 1; + } + } + return 0; +} + void DeplacementSerpent(int direction ,int *serpent, int longueur) { int tempX = serpent[0]; diff --git a/evenement.h b/evenement.h index ff1162a..57f85d0 100644 --- a/evenement.h +++ b/evenement.h @@ -3,7 +3,7 @@ #ifndef EVENEMENT_H #define EVENEMENT_H -void MangerPastille(int *serpent, PIXELS* pastilles, size_t longueur_serpent, size_t longueur_pastilles); +void MangerPastille(int *serpent, PIXELS* pastilles, size_t longueur_serpent, size_t longueur_pastilles, unsigned long *score); void DeplacementSerpent(int direction ,int *serpent, int longueur); @@ -11,4 +11,6 @@ void InitialiserPastilles(PIXELS *pastilles); void AfficherTimerEtScore(int m,int n,int score); +int PastilleSurSerpent(PIXELS pastille, int *serpent, size_t longueur_serpent); + #endif \ No newline at end of file diff --git a/evenement.o b/evenement.o index aee0172..0000172 100644 Binary files a/evenement.o and b/evenement.o differ diff --git a/main.c b/main.c index c44d0ce..d12ab2e 100644 --- a/main.c +++ b/main.c @@ -27,7 +27,7 @@ PIXELS gen_pastille() { int x_pastille,y_pastille; PIXELS pastille; - + x_pastille= ArrondirPixel(rand()%W_GAME); y_pastille = ArrondirPixel(rand()%H_GAME); @@ -95,7 +95,7 @@ void DessinerScene(PIXELS *pastilles, int *serpent) /* Dessine la scène */ int main() { unsigned char pause = 0; - int score =0; + unsigned long *score =0; unsigned long suivant; int go_on=1; int n = 0; @@ -194,7 +194,7 @@ int main() direction_davant = direction; /* Check si le serpent à le droit de changer de direction */ DeplacementSerpent(direction,serpent,longueur_serpent); - MangerPastille(serpent,pastilles,&longueur_serpent,longueur_pastilles); + MangerPastille(serpent,pastilles,&longueur_serpent,longueur_pastilles,&score); } } diff --git a/main.o b/main.o index 4edcfa0..6de0c94 100644 Binary files a/main.o and b/main.o differ diff --git a/prog b/prog index bd597d8..4e3fa40 100755 Binary files a/prog and b/prog differ