From c1c53b53f2bd66f93eb0c8e616b9e01f606873cf Mon Sep 17 00:00:00 2001 From: stiti Date: Sun, 10 Dec 2023 18:14:02 +0100 Subject: [PATCH] Correction de bugs --- img/bombe.png | Bin 0 -> 4583 bytes include/jeu.h | 2 +- include/timer.h | 12 ++--- src/.vscode/c_cpp_properties.json | 18 ------- src/.vscode/launch.json | 24 --------- src/.vscode/settings.json | 37 ------------- src/jeu.c | 60 +++++++++++---------- src/main.c | 4 ++ src/menu.c | 2 +- src/obstacle.c | 5 +- src/serpent.c | 5 +- src/timer.c | 87 ++++++++++++------------------ 12 files changed, 84 insertions(+), 172 deletions(-) create mode 100644 img/bombe.png delete mode 100644 src/.vscode/c_cpp_properties.json delete mode 100644 src/.vscode/launch.json delete mode 100644 src/.vscode/settings.json diff --git a/img/bombe.png b/img/bombe.png new file mode 100644 index 0000000000000000000000000000000000000000..bafe903298c1f607b537dbb4fc14e6717a48715c GIT binary patch literal 4583 zcmdT{cT|(vwm$)qKnNtXB=jf*LQQB90g+w>X(C0C7MegZA)umz6h)BUi^w1&R-}(0 zDuN{^^{Z_u5bN1Qo{Px-3*(b@))|?L|h5`Wa zSz4GlK&|l3%gqV>HyvKu4**O&$k^B}$k!JDa<8wKmpYUE6N@hB<<;4vq<~@_cSuZ3 zaq!yT+tS|B4G>9PPvB`Vm_9MmGul&;6R{bY8Y^IO^f|oniGkRpl`2^gHgG0pgiQKP zyD&DkA9Oxbr6_<48qZ+0rdhSEi+sdLdy5Q>jGwtW-&vopu8JA4#I6fr?{Uxa5WnzR z{H#;Z(*~md-jQbT zB5&}dyen71u+d8-A`W}56gvol>-%K;Uva_6QpAeh*vVzOux>ooIOfejnL0T;v#WqA z?cFZHgFtMTqtVJ|us(7R&}d#Zfv|aPciRwJl)$wrN?7lKftL1z-}HcPB!m{x*TTUD zfG9ZtV$K4v1(9NA0f?XiFz*F`P5}UTW^t3f9snH4b_bkHA%>?2u5Dgq3;^)}Kr&eX zH!zLo(Ims!GYn&sHsw}6k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RyRnR--MxF27nmUE#uz;s#Dnfx3`R(f1qsmJ>3sdT$Ds4^msQ=VqkWjY_Qs z4VY#wIn9)5ALse5y$U(TQ-1_z2eLIpS*(tY>DSYfr{{$t&nz5oJ}TO3Co@X_I`8e- zv0!8saQ?+n%$$Ai$I}NcKnud}fIvSH|@NbV}u9otScxi0H{@9VxWo(?Ac*~ z3SAvv2J<8X>wkH~^z+yGo4t`Y%ljQ-dAJh=ryzC+{l6Fg8DoK+ zE0e?yGEf1fW4yD=87wCTBjkUigRz1UFT{ubi_gKEy%QYT^kHToM7R7W-C-v#;W~%u zK8|b%_)vNn8w9f1%y1nFF(_)P VRLa}5YtUT>(rRjJQfcHB_YXF7DN6tV literal 0 HcmV?d00001 diff --git a/include/jeu.h b/include/jeu.h index 72a9f88..076ee4f 100644 --- a/include/jeu.h +++ b/include/jeu.h @@ -2,12 +2,12 @@ #define JEU_H + void afficherScore(int score); void lancer_jeu1(void); void lancer_jeu2(void); void lancer_jeu3(void); void lancer_jeu4(void); -void lancer_jeu5(void); #endif /*JEU_H*/ \ No newline at end of file diff --git a/include/timer.h b/include/timer.h index 31a5a0c..fe99123 100644 --- a/include/timer.h +++ b/include/timer.h @@ -1,12 +1,10 @@ #ifndef TIMER_H #define TIMER_H - -unsigned long int attendre(void); -unsigned long int creer_timer(void); -int afficher_minute(int min); +void initialiser_timer(int *min, int *sec); int afficher_seconde(int sec); +int afficher_minute(int min); +void update_timer(int *min, int *sec); +void pause(void); - - -#endif /*TIMER_H*/ \ No newline at end of file +#endif /* TIMER_H */ diff --git a/src/.vscode/c_cpp_properties.json b/src/.vscode/c_cpp_properties.json deleted file mode 100644 index c2098a2..0000000 --- a/src/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "configurations": [ - { - "name": "linux-gcc-x64", - "includePath": [ - "${workspaceFolder}/**" - ], - "compilerPath": "/usr/bin/gcc", - "cStandard": "${default}", - "cppStandard": "${default}", - "intelliSenseMode": "linux-gcc-x64", - "compilerArgs": [ - "" - ] - } - ], - "version": 4 -} \ No newline at end of file diff --git a/src/.vscode/launch.json b/src/.vscode/launch.json deleted file mode 100644 index 4b3737f..0000000 --- a/src/.vscode/launch.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "C/C++ Runner: Debug Session", - "type": "cppdbg", - "request": "launch", - "args": [], - "stopAtEntry": false, - "externalConsole": false, - "cwd": "/export/home/an23/stiti/PROJET DEV/SAE11_2023/src", - "program": "/export/home/an23/stiti/PROJET DEV/SAE11_2023/src/build/Debug/outDebug", - "MIMode": "gdb", - "miDebuggerPath": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - } - ] -} \ No newline at end of file diff --git a/src/.vscode/settings.json b/src/.vscode/settings.json deleted file mode 100644 index 450db55..0000000 --- a/src/.vscode/settings.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "C_Cpp_Runner.cCompilerPath": "gcc", - "C_Cpp_Runner.cppCompilerPath": "g++", - "C_Cpp_Runner.debuggerPath": "gdb", - "C_Cpp_Runner.cStandard": "", - "C_Cpp_Runner.cppStandard": "", - "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", - "C_Cpp_Runner.useMsvc": false, - "C_Cpp_Runner.warnings": [ - "-Wall", - "-Wextra", - "-Wpedantic", - "-Wshadow", - "-Wformat=2", - "-Wconversion", - "-Wnull-dereference", - "-Wsign-conversion" - ], - "C_Cpp_Runner.enableWarnings": true, - "C_Cpp_Runner.warningsAsError": false, - "C_Cpp_Runner.compilerArgs": [], - "C_Cpp_Runner.linkerArgs": [], - "C_Cpp_Runner.includePaths": [], - "C_Cpp_Runner.includeSearch": [ - "*", - "**/*" - ], - "C_Cpp_Runner.excludeSearch": [ - "**/build", - "**/build/**", - "**/.*", - "**/.*/**", - "**/.vscode", - "**/.vscode/**" - ], - "C_Cpp_Runner.useAddressSanitizer": false -} \ No newline at end of file diff --git a/src/jeu.c b/src/jeu.c index d5c3346..1a4ab40 100644 --- a/src/jeu.c +++ b/src/jeu.c @@ -24,6 +24,7 @@ void afficherScore(int score) { void lancer_jeu1(void) { + int fin = 1; Segment serpent[100]; int longueur = 10; int direction_x = 1; @@ -31,20 +32,18 @@ void lancer_jeu1(void) { int score = 0; char scoreStr[20]; Pomme pomme; - - FermerGraphique(); - InitialiserGraphique(); - CreerFenetre(0, 0, 1200, 1000); - ChoisirTitreFenetre("Snake By Moncef & Marco"); + int min, sec; + + initialiser_timer(&min, &sec); initialiserSerpent(serpent, &longueur); dessinerGrille(); pomme = creerPomme(); dessinerPomme(pomme); - - while (1) { + while (fin == 1) { + update_timer(&min, &sec); gestionDeplacements(serpent, &direction_x, &direction_y); mettreAJourSerpent(serpent, &longueur, &direction_x, &direction_y); @@ -58,21 +57,22 @@ void lancer_jeu1(void) { if (tuerSerpent(serpent, longueur)) { int choixGameOver; afficherMenuGameOver(); + afficher_seconde(sec); + afficher_minute(min); afficherScore(score); /* Attend le choix du joueur après le game over */ choixGameOver = attendreChoixGameOver(); } - - - dessinerSerpent(serpent, &longueur); - + dessinerSerpent(serpent, &longueur); afficherScore(score); - + update_timer(&min, &sec); + attendreSerpent(150000); } } + void lancer_jeu2(void) { int i; Segment serpent[100]; @@ -83,12 +83,10 @@ void lancer_jeu2(void) { int score = 0; char scoreStr[20]; Pomme pommes[5]; + int min, sec; - FermerGraphique(); - InitialiserGraphique(); - CreerFenetre(0, 0, 1200, 1000); - ChoisirTitreFenetre("Snake By Moncef & Marco"); + initialiser_timer(&min, &sec); initialiserSerpent(serpent, &longueur); dessinerGrille(); @@ -113,6 +111,9 @@ void lancer_jeu2(void) { if (tuerSerpent(serpent, longueur)) { int choixGameOver; afficherMenuGameOver(); + afficher_seconde(sec); + afficher_minute(min); + afficherScore(score); /* Attend le choix du joueur après le game over */ choixGameOver = attendreChoixGameOver(); @@ -121,8 +122,9 @@ void lancer_jeu2(void) { dessinerSerpent(serpent, &longueur); afficherScore(score); + update_timer(&min, &sec); - attendreSerpent(vitesse); + attendreSerpent(vitesse); /*Gère la vitesse*/ } } @@ -136,13 +138,10 @@ void lancer_jeu4(void) { char scoreStr[20]; Pomme pomme; Segment serpent[100]; + int min, sec; - FermerGraphique(); - InitialiserGraphique(); - CreerFenetre(0, 0, 1200, 1000); - ChoisirTitreFenetre("Snake By Moncef & Marco"); - + initialiser_timer(&min, &sec); initialiserSerpent(serpent, &longueur); dessinerGrille(); @@ -173,6 +172,7 @@ void lancer_jeu4(void) { dessinerSerpent(serpent, &longueur); afficherScore(score); + update_timer(&min, &sec); attendreSerpent(vitesse); } @@ -190,14 +190,9 @@ void lancer_jeu3(void) { int nombreObstacles = 10; Obstacle *obstacles = malloc(nombreObstacles * sizeof(Obstacle)); Segment serpent[100]; + int min, sec; - - - FermerGraphique(); - InitialiserGraphique(); - CreerFenetre(0, 0, 1200, 1000); - ChoisirTitreFenetre("Snake By Moncef & Marco"); - + initialiser_timer(&min, &sec); initialiserSerpent(serpent, &longueur); dessinerGrille(); @@ -223,6 +218,8 @@ void lancer_jeu3(void) { if (tuerSerpent(serpent, longueur)) { int choixGameOver; afficherMenuGameOver(); + afficher_seconde(sec); + afficher_minute(min); afficherScore(score); /* Attend le choix du joueur après le game over */ choixGameOver = attendreChoixGameOver(); @@ -233,6 +230,9 @@ void lancer_jeu3(void) { if (estCollisionObstacle(obstacles[i], serpent, longueur)) { int choixGameOver; afficherMenuGameOver(); + afficher_seconde(sec); + afficher_minute(min); + afficherScore(score); /* Attend le choix du joueur après le game over */ choixGameOver = attendreChoixGameOver(); @@ -259,6 +259,8 @@ void lancer_jeu3(void) { } afficherScore(score); + update_timer(&min, &sec); + /*Attendre en fonction de la vitesse actuelle*/ attendreSerpent(vitesse); diff --git a/src/main.c b/src/main.c index 027b08e..0c40d77 100644 --- a/src/main.c +++ b/src/main.c @@ -20,15 +20,19 @@ int main(void) { afficherMenuModesDeJeu(); choixModesDeJeu = attendreChoixModesDeJeu(); if(choixModesDeJeu == 1){ + EffacerEcran(CouleurParNom("white")); lancer_jeu1(); } if(choixModesDeJeu == 2){ + EffacerEcran(CouleurParNom("white")); lancer_jeu2(); } if(choixModesDeJeu == 3){ + EffacerEcran(CouleurParNom("white")); lancer_jeu3(); } if(choixModesDeJeu == 4){ + EffacerEcran(CouleurParNom("white")); lancer_jeu4(); } } else if (choixMenuPrincipal == 2) { diff --git a/src/menu.c b/src/menu.c index 3b7b8f5..050c730 100644 --- a/src/menu.c +++ b/src/menu.c @@ -49,7 +49,7 @@ int attendreChoixGameOver() { /* Vérifie si le bouton "Menu Principal" est cliqué */ if (x >= 379 && x <= 830.7 && y >= 530.3 && y <= 670.1) { - FermerGraphique(); + EffacerEcran(CouleurParNom("white")); main(); /* Renvoie vers le menu principal" */ } diff --git a/src/obstacle.c b/src/obstacle.c index 434b90e..80d5111 100644 --- a/src/obstacle.c +++ b/src/obstacle.c @@ -10,8 +10,9 @@ void dessinerObstacle(Obstacle obstacle) { - ChoisirCouleurDessin(CouleurParComposante(10, 10, 10)); /*choix de la couleur de l'opstacle */ - RemplirRectangle(obstacle.x * TAILLE_CASE, obstacle.y * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE); + int id_bombe; + id_bombe = ChargerSprite("../img/bombe.png"); + AfficherSprite(id_bombe,obstacle.x * TAILLE_CASE, obstacle.y * TAILLE_CASE); } diff --git a/src/serpent.c b/src/serpent.c index 434a08b..b48a403 100644 --- a/src/serpent.c +++ b/src/serpent.c @@ -2,6 +2,7 @@ #include #include "../include/serpent.h" #include "../include/main.h" +#include "../include/timer.h" #define TAILLE_CASE 20 #define LARGEUR_GRILLE 60 #define HAUTEUR_GRILLE 40 @@ -39,7 +40,9 @@ void gestionDeplacements(Segment serpent[], int *direction_x, int *direction_y) } else if (touche == XK_Escape) { FermerGraphique(); main(); - } + } else if (touche == XK_space) { + pause(); + } } } diff --git a/src/timer.c b/src/timer.c index 8362f2d..3842b7f 100644 --- a/src/timer.c +++ b/src/timer.c @@ -1,23 +1,18 @@ -#include -#include -#include +#include +#include +#include +#include "../include/timer.h" + #define cycle 1000000L -unsigned long int attendre(void) { - unsigned long int temps_pause; - unsigned long int t1 = Microsecondes(); - while (1) { - if (ToucheEnAttente() && Touche() == XK_space) { - break; - } - } - temps_pause = Microsecondes() - t1; - return temps_pause; +void initialiser_timer(int *min, int *sec) { + *min = 0; + *sec = 0; } int afficher_seconde(int sec){ char timer[50]; - int x = 120 ,y = 100; + int x = 230 ,y = 850; if(sec<=9){ ChoisirCouleurDessin(CouleurParComposante(0, 0, 0)); RemplirRectangle(x-3,y-25,40,30); @@ -37,63 +32,51 @@ int afficher_seconde(int sec){ int afficher_minute(int min){ char timer[50]; - int x = 80 ,y = 100; + int x = 190 ,y = 850; if(min<=9){ ChoisirCouleurDessin(CouleurParComposante(0, 0, 0)); RemplirRectangle(x-3,y-25,40,30); ChoisirCouleurDessin(CouleurParComposante(255, 255, 255)); EcrireTexte(x,y,"0",2); snprintf(timer,sizeof(timer),"%d",min); - EcrireTexte(110,100,":",2); + EcrireTexte(x+30,y,":",2); EcrireTexte(x+15,y,timer,2); } else { ChoisirCouleurDessin(CouleurParComposante(0, 0, 0)); RemplirRectangle(x-3,y-25,40,25); ChoisirCouleurDessin(CouleurParComposante(255, 255, 255)); snprintf(timer,sizeof(timer),"%d",min); - EcrireTexte(110,100,":",2); + EcrireTexte(x+30,y,":",2); EcrireTexte(x,y,timer,2); } return min; } -void creer_timer(void){ - int sec = 0,min=0,x=1; - unsigned long int temps = 0,seconde,pause=0; - seconde=Microsecondes()+cycle; - afficher_seconde(sec); - afficher_minute(min); - EcrireTexte(110,100,":",2); - while(x=1){ - if(Microsecondes()>seconde){ - sec++; - afficher_seconde(sec); - seconde=Microsecondes()+cycle; - if(sec==60){ - sec=0; - min++; - afficher_seconde(sec); - afficher_minute(min); - } - - } - if(ToucheEnAttente()==1){ - if(Touche()==XK_space){ - pause=attendre(); - } - if(Touche()==XK_Escape){ - x=0; - } +void update_timer(int *min, int *sec) { + static unsigned long int temps_precedent = 0; + unsigned long int temps_actuel = Microsecondes(); + unsigned long int temps_ecoule = temps_actuel - temps_precedent; + + if (temps_ecoule >= cycle) { + temps_precedent = temps_actuel; + + if (*sec < 59) { + (*sec)++; + } else { + *sec = 0; + (*min)++; } + + /* Afficher le timer */ + afficher_seconde(*sec); + afficher_minute(*min); } } -/* -int main(void){ - InitialiserGraphique(); - CreerFenetre(1000,0,1000,1000); - creer_timer(); - FermerGraphique(); - return EXIT_SUCCESS; +void pause(void) { + while (1) { + if (ToucheEnAttente() && Touche() == XK_space) { + break; + } + } } -*/ \ No newline at end of file