From b205833c66034683736620627ae28dc3a5b6c5db Mon Sep 17 00:00:00 2001 From: Vince <vi.teissier@gmail.com> Date: Fri, 15 Dec 2023 22:58:53 +0100 Subject: [PATCH] =?UTF-8?q?Vrai=20Fix=20Timer=20+=20Am=C3=A9liorations=20g?= =?UTF-8?q?raphiques?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- evenement.c | 52 ++++++++++++++++++--------------------- evenement.h | 2 +- images/PommePastille.png | Bin 0 -> 195 bytes images/SnakePart.png | Bin 0 -> 152 bytes main.c | 48 ++++++++++++++++++++++-------------- 5 files changed, 54 insertions(+), 48 deletions(-) create mode 100644 images/PommePastille.png create mode 100644 images/SnakePart.png diff --git a/evenement.c b/evenement.c index ec2585c..f139992 100644 --- a/evenement.c +++ b/evenement.c @@ -5,29 +5,23 @@ #include <time.h> -void AfficherTimerEtScore(long unsigned int *score, long unsigned int temps) /*Afficher le temps passé et le score*/ +void AfficherTimerEtScore(long unsigned int *score, int minutes,int secondes) /*Afficher le temps passé et le score*/ { char buf[100]; char buff[100]; /* Stockage du score et du timer */ - couleur j; - - time_t fin_temps; - long int timer; - int minutes,secondes; - fin_temps = time(NULL); /* Gestion du timer et des variables */ - timer = difftime(fin_temps, temps); - secondes = timer % 60; - minutes = timer / 60; - - j=CouleurParNom("yellow"); - ChoisirCouleurDessin(j); + couleur text; + text=CouleurParComposante(78, 93, 47); ChoisirEcran(1); - CopierZone(2,1,0,0,930,710,0,0); + CopierZone(2,1,0,0,930,710,0,0); + + ChoisirCouleurDessin(text); + snprintf(buf,100,"TEMPS : %02d:%02d",minutes,secondes); snprintf(buff,100,"SCORE : %07ld",*score); - EcrireTexte(60,650,buf,2); - EcrireTexte(600,650,buff,2); + EcrireTexte(60,675,buf,2); + EcrireTexte(600,675,buff,2); + CopierZone(1,0,0,0,930,710,0,0); } @@ -42,8 +36,7 @@ void InitialiserPastilles(PIXELS *pastilles, PIXELS *serpent, int longueur_serpe for (i = 0; i < PASTILLES; i++) { pastilles[i] = gen_pastille(serpent,pastilles,longueur_serpent); - RemplirRectangle(pastilles[i].x,pastilles[i].y,T_PIXEL,T_PIXEL); - + ChargerImage("./images/PommePastille.png",pastilles[i].x,pastilles[i].y,0,0,T_PIXEL,T_PIXEL); } } @@ -70,7 +63,7 @@ int MangerPastille(PIXELS *serpent, PIXELS* pastilles,unsigned long *score,int l if(serpent[0].x == pastilles[i].x && serpent[0].y == pastilles[i].y) { pastilles[i] = gen_pastille(serpent,pastilles,longueur_serpent); - RemplirRectangle(pastilles[i].x,pastilles[i].y,T_PIXEL,T_PIXEL); + ChargerImage("./images/PommePastille.png",pastilles[i].x,pastilles[i].y,0,0,T_PIXEL,T_PIXEL); *score+=5; return 1; } @@ -93,6 +86,7 @@ int MangerPastille(PIXELS *serpent, PIXELS* pastilles,unsigned long *score,int l return 0; }*/ + void DeplacementSerpent(int direction ,PIXELS *serpent, int longueur) { int tempX = serpent[0].x; @@ -102,7 +96,7 @@ void DeplacementSerpent(int direction ,PIXELS *serpent, int longueur) couleur j; ChoisirEcran(2); j=CouleurParNom("yellow"); - g=CouleurParNom("lightgreen"); + g=CouleurParComposante(171, 204, 104); for (i = 1; i < longueur; i++) { @@ -114,32 +108,34 @@ void DeplacementSerpent(int direction ,PIXELS *serpent, int longueur) tempX = tempX2; tempY = tempY2; + + if(i == longueur-1) + { + ChoisirCouleurDessin(g); + RemplirRectangle(serpent[i].x,serpent[i].y,T_PIXEL,T_PIXEL); + } } - ChoisirCouleurDessin(g); - - RemplirRectangle(serpent[longueur-1].x,serpent[longueur-1].y,T_PIXEL,T_PIXEL); - ChoisirCouleurDessin(j); if(direction == 0) /* Direction vers la gauche */ { serpent[0].x-=T_PIXEL; - RemplirRectangle(serpent[0].x,serpent[0].y,T_PIXEL,T_PIXEL); + ChargerImage("./images/SnakePart.png",serpent[0].x,serpent[0].y,0,0,T_PIXEL,T_PIXEL); } else if(direction == 1) /* Direction vers le haut */ { serpent[0].y-=T_PIXEL; - RemplirRectangle(serpent[0].x,serpent[0].y,T_PIXEL,T_PIXEL); + ChargerImage("./images/SnakePart.png",serpent[0].x,serpent[0].y,0,0,T_PIXEL,T_PIXEL); } else if(direction == 2) /* Direction vers la droite */ { serpent[0].x+=T_PIXEL; - RemplirRectangle(serpent[0].x,serpent[0].y,T_PIXEL,T_PIXEL); + ChargerImage("./images/SnakePart.png",serpent[0].x,serpent[0].y,0,0,T_PIXEL,T_PIXEL); } else if(direction == 3) /* Direction vers le bas */ { serpent[0].y+=T_PIXEL; - RemplirRectangle(serpent[0].x,serpent[0].y,T_PIXEL,T_PIXEL); + ChargerImage("./images/SnakePart.png",serpent[0].x,serpent[0].y,0,0,T_PIXEL,T_PIXEL); } } \ No newline at end of file diff --git a/evenement.h b/evenement.h index 5c3e9af..4c53aee 100644 --- a/evenement.h +++ b/evenement.h @@ -9,7 +9,7 @@ void DeplacementSerpent(int direction ,PIXELS *serpent, int longueur); void InitialiserPastilles(PIXELS *pastilles, PIXELS *serpent, int longueur_serpent); -void AfficherTimerEtScore(long unsigned int *score, long unsigned int temps); +void AfficherTimerEtScore(long unsigned int *score,int minutes,int secondes); int PastilleSurSerpent(PIXELS pastille, PIXELS *serpent, int longueur_serpent); diff --git a/images/PommePastille.png b/images/PommePastille.png new file mode 100644 index 0000000000000000000000000000000000000000..543dd55c8834f5216d27e3de40241a55d1ce31c2 GIT binary patch literal 195 zcmeAS@N?(olHy`uVBq!ia0vp^{2<K11|+SoP4xm&jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85m^SL71`s>Bm%{V1%cOV~B-+azmrBP|^R+qXD`c3_>;9i=6}( zXSkUO&Q2=nSu-y~dg8|enQRXO&#EL%GC9o9!+)LU@QJQOiDisz6RtW7YZhi!FIph6 lN=?GSY@$Hhi-ZIQ2EVySZpuA#GzHqh;OXk;vd$@?2>^XMJ9_{C literal 0 HcmV?d00001 diff --git a/images/SnakePart.png b/images/SnakePart.png new file mode 100644 index 0000000000000000000000000000000000000000..453efe1b2d17a68be4adf7ab7971db1f4cd0e830 GIT binary patch literal 152 zcmeAS@N?(olHy`uVBq!ia0vp^{2<K11|+SoP4xm&jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85m^SL71`s>Bm%{psuHjV~B-+asy*3^TPi}l2(YZ99YI7-j=24 pD{Liq)kg`0+th+~rSq_{F?8He+A=HG<}^?vgQu&X%Q~loCIDDlC|Upj literal 0 HcmV?d00001 diff --git a/main.c b/main.c index d1d464e..8a55384 100644 --- a/main.c +++ b/main.c @@ -6,6 +6,7 @@ #include "main.h" #define delta 100000L +#define delta2 1000000L int ArrondirPixel(int nombre) /* Calcule un arrondi du pixel pour pouvoir respecter la norme des 40 lignes et 60 colonnes */ { @@ -68,7 +69,7 @@ void InitialisationDuSerpent(PIXELS *p_serpent) /* L'initialisation du serpent * x_millieu = T_PIXEL*30; /* 30 = 60 colonnes divisé par 2*/ y_millieu = T_PIXEL*20; /* 20 = 40 colonnes divisé par 2*/ ChoisirEcran(2); - RemplirRectangle(x_millieu,y_millieu,T_PIXEL,T_PIXEL); + ChargerImage("./images/SnakePart.png",x_millieu,y_millieu,0,0,T_PIXEL,T_PIXEL); /* printf("x_millieu : %d | y_millieu : %d\n",x_millieu,y_millieu); DEBUG*/ @@ -81,16 +82,24 @@ void InitialisationDuSerpent(PIXELS *p_serpent) /* L'initialisation du serpent * /*printf("x_millieu : %d | y_millieu : %d\n",p_serpent[compteur+2],p_serpent[compteur+3]); DEBUG*/ - RemplirRectangle(p_serpent[compteur+1].x,p_serpent[compteur+1].y,T_PIXEL,T_PIXEL); + ChargerImage("./images/SnakePart.png",p_serpent[compteur+1].x,p_serpent[compteur+1].y,0,0,T_PIXEL,T_PIXEL); } } void DessinerScene(PIXELS *pastilles, PIXELS *serpent, int longueur_serpent) /* Dessine la scène */ { - couleur c; + couleur bg; + couleur border; ChoisirEcran(2); - c=CouleurParNom("lightgreen"); - ChoisirCouleurDessin(c); + border=CouleurParComposante(78, 93, 47); + bg=CouleurParComposante(171, 204, 104); + + ChoisirCouleurDessin(border); + RemplirRectangle(0,0,930,635); + + ChoisirCouleurDessin(bg); + RemplirRectangle(0,635,930,650); + RemplirRectangle(T_PIXEL,T_PIXEL,W_GAME,H_GAME); InitialiserPastilles(pastilles,serpent,longueur_serpent); InitialisationDuSerpent(serpent); @@ -102,11 +111,11 @@ int main() unsigned char pause = 0; unsigned long score =0; unsigned long suivant; + unsigned long suivant2; int go_on=1; - int n = 0; - int m = 0; + int secondes = 0; + int minutes = 0; - time_t temps; size_t longueur_serpent = 12; size_t longueur_pastilles = PASTILLES; @@ -116,8 +125,6 @@ int main() int direction = 0; int direction_davant = 0; - temps = time(NULL); /*Première mesure du temps*/ - if(serpent == NULL) { fprintf(stderr, "Erreur d'allocation de mémoire.\n"); return EXIT_FAILURE; @@ -183,19 +190,22 @@ int main() else { if(pause==0){ + if (Microsecondes()>suivant2) + { + secondes++; + if(secondes == 60) + { + minutes++; + secondes = 0; + } + suivant2=Microsecondes()+delta2; + } + if (Microsecondes()>suivant) { - n++; - if(n%60==0) - { - m++; - n=0; - } - - AfficherTimerEtScore(&score,temps); suivant=Microsecondes()+delta; - + AfficherTimerEtScore(&score,minutes,secondes); direction_davant = direction; /* Check si le serpent à le droit de changer de direction */ MourrirSerpent(serpent,longueur_serpent); DeplacementSerpent(direction,serpent,longueur_serpent);