From 887caed23960033ace14723b13ae4d439a558069 Mon Sep 17 00:00:00 2001 From: Vince <vi.teissier@gmail.com> Date: Thu, 21 Dec 2023 14:32:55 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liration=20Graphique=20(=20non=20fini?= =?UTF-8?q?=20)=20+=20code=20plus=20facile=20a=20lire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 8 +- evenement.c | 17 +--- evenement.h | 2 +- gui.c | 21 ++++ gui.h | 10 ++ images/{PERDU.png => Perdu.png} | Bin main.c | 164 +++++++++++--------------------- prog | Bin 21504 -> 21568 bytes scene.c | 113 ++++++++++++++++++++++ scene.h | 10 ++ 10 files changed, 217 insertions(+), 128 deletions(-) create mode 100644 gui.c create mode 100644 gui.h rename images/{PERDU.png => Perdu.png} (100%) create mode 100644 scene.c create mode 100644 scene.h diff --git a/Makefile b/Makefile index 1747d20..1ea5a49 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CFLAGS = -Wall -Wextra all: prog -prog: main.o evenement.o GUI.o +prog: main.o evenement.o gui.o scene.o $(CC) -o $@ $^ -lgraph main.o: main.c evenement.h @@ -12,8 +12,12 @@ main.o: main.c evenement.h evenement.o: evenement.c evenement.h $(CC) $(CFLAGS) -c $< -o $@ -GUI.o: GUI.c GUI.h +gui.o: gui.c gui.h $(CC) $(CFLAGS) -c $< -o $@ +scene.o: scene.c scene.h + $(CC) $(CFLAGS) -c $< -o $@ + + clean: rm -f *.o prog diff --git a/evenement.c b/evenement.c index 2bc7c50..6c39fb1 100644 --- a/evenement.c +++ b/evenement.c @@ -3,7 +3,8 @@ #include <stdlib.h> #include <time.h> #include "main.h" -#include "GUI.h" +#include "gui.h" +#include "scene.h" void AfficherTimerEtScore(long unsigned int *score, int minutes,int secondes) /*Afficher le temps passé et le score*/ { @@ -25,17 +26,6 @@ void AfficherTimerEtScore(long unsigned int *score, int minutes,int secondes) CopierZone(1,0,0,0,930,710,0,0); } -void InitialiserPastilles(PIXELS *pastilles, PIXELS *serpent, int longueur_serpent) { - int i; - - srand(time(NULL)); - - for (i = 0; i < PASTILLES; i++) { - pastilles[i] = gen_pastille(serpent,pastilles,longueur_serpent); - ChargerImage("./images/PommePastille.png",pastilles[i].x,pastilles[i].y,0,0,T_PIXEL,T_PIXEL); - } -} - int MourrirSerpent(PIXELS *serpent, int longueur_serpent) { int i = 0; @@ -94,7 +84,6 @@ void DeplacementSerpent(int direction ,PIXELS *serpent, int longueur) tempY = tempY2; } - if(direction == 0) /* Direction vers la gauche */ { serpent[0].x-=T_PIXEL; @@ -117,7 +106,7 @@ void DeplacementSerpent(int direction ,PIXELS *serpent, int longueur) } } -int Serpent(PIXELS *serpent,PIXELS *pastilles,unsigned long *score,int *longueur_serpent,unsigned long int *vitesse,int direction) +int Serpent(PIXELS *serpent,PIXELS *pastilles,unsigned long *score,unsigned long *longueur_serpent,unsigned long int *vitesse,int direction) { if(MourrirSerpent(serpent,*longueur_serpent) == 1) { diff --git a/evenement.h b/evenement.h index 3fbd7c7..ea85f25 100644 --- a/evenement.h +++ b/evenement.h @@ -15,7 +15,7 @@ int PastilleSurSerpent(PIXELS pastille, PIXELS *serpent, int longueur_serpent); int MourrirSerpent(PIXELS *serpent, int longueur_serpent); -int Serpent(PIXELS *serpent,PIXELS *pastilles,unsigned long *score,int *longueur_serpent,unsigned long int *vitesse,int direction); +int Serpent(PIXELS *serpent,PIXELS *pastilles,unsigned long *score,unsigned long *longueur_serpent,unsigned long int *vitesse,int direction); #endif \ No newline at end of file diff --git a/gui.c b/gui.c new file mode 100644 index 0000000..f887ed0 --- /dev/null +++ b/gui.c @@ -0,0 +1,21 @@ +#include <stdlib.h> +#include <stdio.h> +#include <graph.h> + +void Menu() +{ + ChoisirEcran(0); + ChargerImage("./images/Menu.png",0,0,0,0,930,710); +} + +void Pause() +{ + ChoisirEcran(0); + ChargerImage("./images/Pause.png",0,0,0,0,930,710); +} + +void PerduGUI() +{ + ChoisirEcran(0); + ChargerImage("./images/Perdu.png",0,0,0,0,930,710); +} \ No newline at end of file diff --git a/gui.h b/gui.h new file mode 100644 index 0000000..007bbaf --- /dev/null +++ b/gui.h @@ -0,0 +1,10 @@ +#ifndef GUI_H +#define GUI_H + +void Menu(); +void PerduGUI(); +void Pause(); +void Reinitialiser(); +int AfficherGUI(unsigned char menu); + +#endif \ No newline at end of file diff --git a/images/PERDU.png b/images/Perdu.png similarity index 100% rename from images/PERDU.png rename to images/Perdu.png diff --git a/main.c b/main.c index d770ff0..6c51310 100644 --- a/main.c +++ b/main.c @@ -4,107 +4,12 @@ #include <time.h> #include "evenement.h" #include "main.h" -#include "GUI.h" +#include "gui.h" +#include "scene.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 */ -{ - /* Calcul du reste de la division par 15 */ - int reste = nombre % 15; - - /* Calcul de l'arrondi au multiple de 15 le plus proche */ - int arrondi = (reste <= 7) ? nombre - reste : nombre + (15 - reste); - - return arrondi; -} - -PIXELS gen_pastille(PIXELS *serpent,PIXELS *pastilles,int longueur_serpent) - - /* nb_pastille = int nombre de pastille voulue , p_pastilles est un pointeur d'un tableau de pixels qui sont des pastilles*/ - /*-Elles se génèrent à des endroits qui peuvent être les mêmes ou gêner le snake*/ -{ - int x_pastille,y_pastille,i; - int ok = 0; - PIXELS pastille; - do{ - ok = 0; - x_pastille= ArrondirPixel(rand()%W_GAME); - y_pastille = ArrondirPixel(rand()%H_GAME); - for(i=0;i<longueur_serpent;i++) - { - if(x_pastille == serpent[i].x && y_pastille == serpent[i].y) - { - ok = 1; /* Check si la pastille se genère sur une coordonné du serpent */ - } - if(x_pastille == pastilles[i].x && y_pastille == pastilles[i].y) - { - ok = 1; - } - - } - }while(ok); - - if(x_pastille < DECALEMENT) - { - x_pastille =+ DECALEMENT; - } - - if(y_pastille < DECALEMENT) - { - y_pastille =+ DECALEMENT; - } - - - pastille.x = x_pastille ; - pastille.y = y_pastille ; - - return pastille; -} - -void InitialisationDuSerpent(PIXELS *p_serpent) /* L'initialisation du serpent */ -{ - int x_millieu = 0, y_millieu = 0 , compteur = 0; - x_millieu = T_PIXEL*30; /* 30 = 60 colonnes divisé par 2*/ - y_millieu = T_PIXEL*20; /* 20 = 40 colonnes divisé par 2*/ - ChoisirEcran(2); - ChargerImage("./images/SnakePart.png",x_millieu,y_millieu,0,0,T_PIXEL,T_PIXEL); - - p_serpent[0].x = x_millieu; - p_serpent[0].y = y_millieu; - for(compteur=0;compteur<9;compteur++) /*Commence par 1 car p_serpent index 0 initialisées pour la tête et 2 + 2x9 = 10 couples de coordonnées 2D */ - { - p_serpent[compteur+1].x = p_serpent[compteur].x+T_PIXEL; - p_serpent[compteur+1].y = p_serpent[compteur].y; - - 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 bg; - couleur border; - ChoisirEcran(2); - border=CouleurParComposante(78, 93, 47); - bg=CouleurParComposante(171, 204, 104); - - ChoisirCouleurDessin(border); - RemplirRectangle(0,0,930,630); - - ChoisirCouleurDessin(bg); - RemplirRectangle(0,630,930,650); - - ChoisirCouleurDessin(border); - RemplirRectangle(0,650,930,15); - - ChoisirCouleurDessin(bg); - RemplirRectangle(T_PIXEL,T_PIXEL,W_GAME,H_GAME); - InitialiserPastilles(pastilles,serpent,longueur_serpent); - InitialisationDuSerpent(serpent); -} - int main() { unsigned char pause = 0; @@ -117,6 +22,7 @@ int main() int minutes = 0; unsigned long int vitesse = DELTA; int valeur_retourne = 0; + unsigned char perdu = 0; size_t longueur_serpent = 10; size_t longueur_pastilles = PASTILLES; @@ -141,16 +47,43 @@ int main() DessinerScene(pastilles,serpent,longueur_serpent); while(window_on) { - ChoisirEcran(0); - Menu(); - if (ToucheEnAttente() == 1) + if(perdu == 1) { - switch (Touche()) + PerduGUI(); + if (ToucheEnAttente() == 1) { - case XK_space: - game_on=1; - DessinerScene(pastilles,serpent,longueur_serpent); - break; + switch (Touche()) + { + case XK_Return: + perdu = 0; + break; + } + } + } + else + { + Menu(); + if (ToucheEnAttente() == 1) + { + switch (Touche()) + { + case XK_Return : + game_on=1; + secondes = 0; + minutes = 0; + score = 0; + vitesse = DELTA; + longueur_serpent = 10; + direction = 0; + direction_davant = 0; + DessinerScene(pastilles,serpent,longueur_serpent); + break; + case XK_Escape: + free(serpent); + free(pastilles); + FermerGraphique(); + return EXIT_SUCCESS; + } } } @@ -195,16 +128,23 @@ int main() pause=1; break; } - else if(pause == 1) - { pause=0; break; + + case XK_Escape: + if(pause == 1) + { + free(serpent); + free(pastilles); + FermerGraphique(); + return EXIT_SUCCESS; } - } + break; + } + if(pause==1) { - ChoisirEcran(0); Pause(); } @@ -226,6 +166,7 @@ int main() if (Microsecondes()>suivant) { + serpent = (PIXELS*) realloc(serpent,longueur_serpent * sizeof(PIXELS)); suivant=Microsecondes()+vitesse; AfficherTimerEtScore(&score,minutes,secondes); direction_davant = direction; /* Check si le serpent à le droit de changer de direction */ @@ -233,10 +174,10 @@ int main() valeur_retourne = Serpent(serpent,pastilles,&score,&longueur_serpent,&vitesse,direction); if(valeur_retourne == 1) { - serpent = (PIXELS*) realloc(serpent,longueur_serpent * sizeof(PIXELS)); } else if (valeur_retourne == 2) { + perdu=1; game_on=0; } } @@ -244,7 +185,8 @@ int main() } } } - + free(serpent); + free(pastilles); FermerGraphique(); return EXIT_SUCCESS; } diff --git a/prog b/prog index 3ee3a30932c830f682f703ec88f8276e29c4253a..43034113fc8812dc939672b71457e898e6b9c4e1 100755 GIT binary patch delta 5126 zcmZ`-4OEm>8ouA~H!}>)3@{D@!VDmasr;BGrX!e6ew07>w};I%Q2{kEO~%dB&VnK8 zh}7uYX<M})b303`drmg)NjxXOQqetWx>>8OyJ5R+gP<X5jhTJ>-0ug`>T<a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ud30?>FL?FpwoyqNS=~BQc4sY_Og=fe&#hX z=}afRR&tx&Jo~dU>0c%H@H3QN?4`mPiru{8p&a`8j60n*xrSSl&Z2EIvPmh;*<7mF z%mNcbp3*#<dD#`3TbdWHbILfwK__i1)#6%Z22udJXy?pfw#12sJep3=%(Ho?7^5U) G$opT(@9(|< diff --git a/scene.c b/scene.c new file mode 100644 index 0000000..4c14736 --- /dev/null +++ b/scene.c @@ -0,0 +1,113 @@ +#include <graph.h> +#include <time.h> +#include <stdlib.h> +#include "main.h" + + + +int ArrondirPixel(int nombre) /* Calcule un arrondi du pixel pour pouvoir respecter la norme des 40 lignes et 60 colonnes */ +{ + /* Calcul du reste de la division par 15 */ + int reste = nombre % 15; + + /* Calcul de l'arrondi au multiple de 15 le plus proche */ + int arrondi = (reste <= 7) ? nombre - reste : nombre + (15 - reste); + + return arrondi; +} + +PIXELS gen_pastille(PIXELS *serpent,PIXELS *pastilles,int longueur_serpent) + + /* nb_pastille = int nombre de pastille voulue , p_pastilles est un pointeur d'un tableau de pixels qui sont des pastilles*/ + /*-Elles se génèrent à des endroits qui peuvent être les mêmes ou gêner le snake*/ +{ + int x_pastille,y_pastille,i; + int ok = 0; + PIXELS pastille; + do{ + ok = 0; + x_pastille= ArrondirPixel(rand()%W_GAME); + y_pastille = ArrondirPixel(rand()%H_GAME); + for(i=0;i<longueur_serpent;i++) + { + if(x_pastille == serpent[i].x && y_pastille == serpent[i].y) + { + ok = 1; /* Check si la pastille se genère sur une coordonné du serpent */ + } + if(x_pastille == pastilles[i].x && y_pastille == pastilles[i].y) + { + ok = 1; + } + + } + }while(ok); + + if(x_pastille < DECALEMENT) + { + x_pastille =+ DECALEMENT; + } + + if(y_pastille < DECALEMENT) + { + y_pastille =+ DECALEMENT; + } + + + pastille.x = x_pastille ; + pastille.y = y_pastille ; + + return pastille; +} + +void InitialisationDuSerpent(PIXELS *p_serpent) /* L'initialisation du serpent */ +{ + int x_millieu = 0, y_millieu = 0 , compteur = 0; + x_millieu = T_PIXEL*30; /* 30 = 60 colonnes divisé par 2*/ + y_millieu = T_PIXEL*20; /* 20 = 40 colonnes divisé par 2*/ + ChoisirEcran(2); + ChargerImage("./images/SnakePart.png",x_millieu,y_millieu,0,0,T_PIXEL,T_PIXEL); + + p_serpent[0].x = x_millieu; + p_serpent[0].y = y_millieu; + for(compteur=0;compteur<9;compteur++) /*Commence par 1 car p_serpent index 0 initialisées pour la tête et 2 + 2x9 = 10 couples de coordonnées 2D */ + { + p_serpent[compteur+1].x = p_serpent[compteur].x+T_PIXEL; + p_serpent[compteur+1].y = p_serpent[compteur].y; + + ChargerImage("./images/SnakePart.png",p_serpent[compteur+1].x,p_serpent[compteur+1].y,0,0,T_PIXEL,T_PIXEL); + } +} + +void InitialiserPastilles(PIXELS *pastilles, PIXELS *serpent, int longueur_serpent) { + int i; + + srand(time(NULL)); + + for (i = 0; i < PASTILLES; i++) { + pastilles[i] = gen_pastille(serpent,pastilles,longueur_serpent); + ChargerImage("./images/PommePastille.png",pastilles[i].x,pastilles[i].y,0,0,T_PIXEL,T_PIXEL); + } +} + +void DessinerScene(PIXELS *pastilles, PIXELS *serpent, int longueur_serpent) /* Dessine la scène */ +{ + couleur bg; + couleur border; + ChoisirEcran(2); + border=CouleurParComposante(78, 93, 47); + bg=CouleurParComposante(171, 204, 104); + + ChoisirCouleurDessin(border); + RemplirRectangle(0,0,930,630); + + ChoisirCouleurDessin(bg); + RemplirRectangle(0,630,930,650); + + ChoisirCouleurDessin(border); + RemplirRectangle(0,650,930,15); + + ChoisirCouleurDessin(bg); + RemplirRectangle(T_PIXEL,T_PIXEL,W_GAME,H_GAME); + InitialiserPastilles(pastilles,serpent,longueur_serpent); + InitialisationDuSerpent(serpent); +} \ No newline at end of file diff --git a/scene.h b/scene.h new file mode 100644 index 0000000..e7ffc2e --- /dev/null +++ b/scene.h @@ -0,0 +1,10 @@ +#include "main.h" + +#ifndef SCENE_H +#define SCENE_H + +void InitialiserPastilles(PIXELS *pastilles, PIXELS *serpent, int longueur_serpent); +PIXELS gen_pastille(PIXELS *serpent,PIXELS *pastilles,int longueur_serpent); +void DessinerScene(PIXELS *pastilles, PIXELS *serpent, int longueur_serpent); + +#endif \ No newline at end of file