From 29ed7dc6dfc5de330a62c22a4d1be6db3ae7a686 Mon Sep 17 00:00:00 2001 From: boutarci Date: Fri, 22 Dec 2023 15:11:29 +0100 Subject: [PATCH] =?UTF-8?q?R=C3=A9glage=20time,=20r=C3=A9glage=20usleep,?= =?UTF-8?q?=20r=C3=A9glage=20menu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SAE_semestre1/Makefile | 40 ++-- SAE_semestre1/{ => fichier.h}/Oeuf.h | 2 +- SAE_semestre1/{ => fichier.h}/fonctions.h | 0 SAE_semestre1/{ => fichier.h}/main.h | 2 + SAE_semestre1/{ => fichier.h}/menu.h | 0 SAE_semestre1/{ => fichier.h}/serpent.h | 0 SAE_semestre1/fichier.h/terrain.h | 6 + SAE_semestre1/{ => fichier.h}/time.h | 0 SAE_semestre1/game.c | 234 ---------------------- SAE_semestre1/img/queue.png | Bin 0 -> 4714 bytes SAE_semestre1/snake | Bin 0 -> 21216 bytes SAE_semestre1/{ => src}/Oeuf.c | 12 +- SAE_semestre1/{ => src}/main.c | 26 ++- SAE_semestre1/{ => src}/menu.c | 21 +- SAE_semestre1/{ => src}/serpent.c | 41 ++-- SAE_semestre1/{ => src}/terrain.c | 16 +- SAE_semestre1/{ => src}/time.c | 9 +- SAE_semestre1/terrain.h | 6 - 18 files changed, 99 insertions(+), 316 deletions(-) rename SAE_semestre1/{ => fichier.h}/Oeuf.h (64%) rename SAE_semestre1/{ => fichier.h}/fonctions.h (100%) rename SAE_semestre1/{ => fichier.h}/main.h (70%) rename SAE_semestre1/{ => fichier.h}/menu.h (100%) rename SAE_semestre1/{ => fichier.h}/serpent.h (100%) create mode 100755 SAE_semestre1/fichier.h/terrain.h rename SAE_semestre1/{ => fichier.h}/time.h (100%) delete mode 100755 SAE_semestre1/game.c create mode 100644 SAE_semestre1/img/queue.png create mode 100755 SAE_semestre1/snake rename SAE_semestre1/{ => src}/Oeuf.c (62%) rename SAE_semestre1/{ => src}/main.c (81%) rename SAE_semestre1/{ => src}/menu.c (71%) rename SAE_semestre1/{ => src}/serpent.c (68%) rename SAE_semestre1/{ => src}/terrain.c (54%) rename SAE_semestre1/{ => src}/time.c (90%) delete mode 100755 SAE_semestre1/terrain.h diff --git a/SAE_semestre1/Makefile b/SAE_semestre1/Makefile index 09b5ca8..b6b8bb2 100755 --- a/SAE_semestre1/Makefile +++ b/SAE_semestre1/Makefile @@ -1,29 +1,31 @@ - CC = gcc CFLAGS = -ansi -pedantic -lgraph -OBJS = main.o serpent.o time.o terrain.o Oeuf.o +SRCDIR = ./src +HDIR = ./fichier.h +ODIR = ./out +OFILES = $(subst $(SRCDIR)/,$(ODIR)/,$(subst .c,.o,$(shell find $(SRCDIR)/ -type f))) +EXE = snake +.PHONY: all clean run -snake: $(OBJS) - $(CC) -o snake $(OBJS) $(CFLAGS) +all: $(EXE) -main.o: serpent.h time.h Oeuf.h main.h menu.h - $(CC) -c main.c $(CFLAGS) +$(ODIR)/%.o : $(SRCDIR)/%.c + @mkdir -p $(@D) + $(CC) -c $< -o $@ -serpent.o: serpent.h - $(CC) -c serpent.c $(CFLAGS) +$(EXE) : $(OFILES) + $(CC) $(CFLAGS) -o $(EXE) $(OFILES) -menu.o: main.h time.h - $(CC) -c menu.c $(CFLAGS) +run : $(EXE) + ./$(EXE) -time.o: time.h serpent.h main.h - $(CC) -c time.c $(CFLAGS) +clean : + -rm -rf $(ODIR) -Oeuf.o: Oeuf.h time.h - $(CC) -c Oeuf.c $(CFLAGS) +# Nouvelle règle pour la dépendance implicite +$(EXE): $(ODIR)/a.out -terrain.o: terrain.h serpent.h time.h main.h Oeuf.h - $(CC) -c terrain.c $(CFLAGS) - -clean: - rm -f *.o snake \ No newline at end of file +# Nouvelle règle pour construire 'out/a.out' +$(ODIR)/a.out: $(OFILES) + $(CC) $(CFLAGS) -o $@ $(OFILES) \ No newline at end of file diff --git a/SAE_semestre1/Oeuf.h b/SAE_semestre1/fichier.h/Oeuf.h similarity index 64% rename from SAE_semestre1/Oeuf.h rename to SAE_semestre1/fichier.h/Oeuf.h index a998f00..5c28429 100755 --- a/SAE_semestre1/Oeuf.h +++ b/SAE_semestre1/fichier.h/Oeuf.h @@ -2,6 +2,6 @@ #define OEUF_H void InitialiserOeufs(int oeufx[], int oeufy[], int segment); -void Oeuf(int pos_x[], int pos_y[], int oeufx[], int oeufy[], int *segment); +void Oeuf(int old_x[], int old_y[], int oeufx[], int oeufy[], int *segment); #endif diff --git a/SAE_semestre1/fonctions.h b/SAE_semestre1/fichier.h/fonctions.h similarity index 100% rename from SAE_semestre1/fonctions.h rename to SAE_semestre1/fichier.h/fonctions.h diff --git a/SAE_semestre1/main.h b/SAE_semestre1/fichier.h/main.h similarity index 70% rename from SAE_semestre1/main.h rename to SAE_semestre1/fichier.h/main.h index bd08be7..a73dc70 100755 --- a/SAE_semestre1/main.h +++ b/SAE_semestre1/fichier.h/main.h @@ -1,6 +1,8 @@ #ifndef MAIN_H #define MAIN_H + +void attente(int milliseconds); int lancer_jeu(void); int main(void); diff --git a/SAE_semestre1/menu.h b/SAE_semestre1/fichier.h/menu.h similarity index 100% rename from SAE_semestre1/menu.h rename to SAE_semestre1/fichier.h/menu.h diff --git a/SAE_semestre1/serpent.h b/SAE_semestre1/fichier.h/serpent.h similarity index 100% rename from SAE_semestre1/serpent.h rename to SAE_semestre1/fichier.h/serpent.h diff --git a/SAE_semestre1/fichier.h/terrain.h b/SAE_semestre1/fichier.h/terrain.h new file mode 100755 index 0000000..72b9aca --- /dev/null +++ b/SAE_semestre1/fichier.h/terrain.h @@ -0,0 +1,6 @@ +#ifndef TERRAIN_H +#define TERRAIN_H + +void Scene(int murx[], int mury[], int minute, int seconde, char timer []); + +#endif diff --git a/SAE_semestre1/time.h b/SAE_semestre1/fichier.h/time.h similarity index 100% rename from SAE_semestre1/time.h rename to SAE_semestre1/fichier.h/time.h diff --git a/SAE_semestre1/game.c b/SAE_semestre1/game.c deleted file mode 100755 index b5d4e56..0000000 --- a/SAE_semestre1/game.c +++ /dev/null @@ -1,234 +0,0 @@ - -#include -#include -#include -#include -#define CYCLE 100000L - -void DessinerScene(int murx[], int mury[], int minute, int seconde, char timer []){ - int mur; - int i; - snprintf(timer,6,"%02d:%02d", minute ,seconde); - ChoisirCouleurDessin(CouleurParComposante(218,209,77)); - RemplirRectangle(20,20,1160,700); - ChoisirCouleurDessin(CouleurParComposante(255,255,255)); - srand(time(NULL)); - for(i=0; i<30; i++){ - murx[i] = ((rand() % (55)+1)*20); - mury[i] = ((rand() % (35)+1)*20); - ChargerImage("../img/cactus.png", murx[i], mury[i],0,0, 20,20); - } -} -void Score(int segment){ - int nombre; - char score[4]; - nombre= (segment-10)*25; - snprintf(score,4,"%04d0", nombre); - ChoisirCouleurDessin(CouleurParNom("black")); - RemplirRectangle(1100,700,1200,800); - ChoisirCouleurDessin(CouleurParNom("white")); - EcrireTexte(1000,760,"Score: ",2); - EcrireTexte(1100,760,score,2); -} -void Update_Timer(int minute, int seconde, char timer[]){ - snprintf(timer,6,"%02d:%02d", minute, seconde); - ChoisirCouleurDessin(CouleurParComposante(0,0,0)); - RemplirRectangle(10,700,12000,800); - ChoisirCouleurDessin(CouleurParComposante(255,255,255)); - EcrireTexte(50,760,"time: ",2); - EcrireTexte(120,760,timer,2); -} -void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[], int* direction){ - int i = 0; - for (i=1 ; i1160 || pos_x[0]<=0){ - *go_on=0; - } - /*Serpent contre coté*/ - if (pos_y[0]<20 || pos_y[0] >=700){ - *go_on=0; - } - /*Serpent contre Serpent*/ - for (i = 1; i < segment; i++) { - if (pos_x[0] == pos_x[i] && pos_y[0] == pos_y[i]){ - *go_on = 0; - } - } - /*Serpent contre mur*/ - for(i=0; i<30;i++){ - if(pos_x[0] == murx[i] && pos_y[0] == mury[i]){ - *go_on=0; - } - } -} -void Timer(int *minute, int *seconde, unsigned long int *suivant, int *seconde_actuel, int *old_seconde, char timer[]){ - if(Microsecondes()> *suivant){ - *suivant = Microsecondes()+CYCLE; - *seconde_actuel = (*suivant/1000000)%10; - if(seconde_actuel !=old_seconde){ - *old_seconde = *seconde_actuel; - if(*seconde == 59){ - *minute=*minute+1; - *seconde=0; - Update_Timer(*minute, *seconde, timer); - }else{ - *seconde = *seconde+1; - Update_Timer(*minute, *seconde, timer); - } - } - } -} -void Controle(int *direction, int last_direction, int *go_on) { - int t; - while(ToucheEnAttente()) { - t = Touche(); - switch(t) { - case XK_Left: - if (last_direction != 4) { - *direction = 3; - } - return; - case XK_Right: - if (last_direction != 3) { - *direction = 4; - } - return; - case XK_Up: - if (last_direction != 2) { - *direction = 1; - } - return; - case XK_Down: - if (last_direction != 1) { - *direction = 2; - } - return; - case XK_Escape: - *direction = 0; - *go_on = 0; - return; - case XK_p: - *direction = 0; - } - } -} -void Serpent(int pos_x[], int pos_y[], int old_x[], int old_y[], int *segment, int murx[], int mury[], int *go_on, int *direction) { - int serpent; - int i = 0; - pos_x[0] = 600; - pos_y[0] = 400; - for (i = 0; i < *segment; i++){ - pos_x[i]= pos_x[0]; - pos_y[i]= pos_y[0]; - old_x[i]=pos_x[i]; - old_y[i]=pos_y[i]; - } -} -void InitialiserOeufs(int oeufx[], int oeufy[], int segment) { - int p; - int oeuf; - for (p = 0; p < 5; p++) { - oeufx[p] = ((rand() % (55) + 1) * 20); - oeuf[p] = ((rand() % (35) + 1) * 20); - ChargerImage("../img/oeuf.png", oeufx[p], oeufy[p],0,0, 20,20); - } -} -void Oeuf(int pos_x[], int pos_y[], int oeufx[], int oeufy[], int *segment){ - int p; - int oeuf; - for (p = 0; p < 5; p++) { - ChargerImage("../img/oeuf.png", oeufx[p], oeufy[p],0,0, 20,20); - } - for(p=0; p<5; p++){ - if(oeufx[p]==pos_x[0] && oeufy[p]==pos_y[0]){ - (*segment) +=2; - oeufx[p] = ((rand() % (55)+1)*20); - oeufy[p] = ((rand() % (35)+1)*20); - } - } -} -/*void Menu_debut(){ - affiche = ChargerSprite("Img/image.png"); - AfficherSprite(affiche,0,0); -} -Menu_debut();*/ - - -int main(void){ - int segment = 10; - int go_on = 1; - int direction = 4; - int minute = 0; - int seconde = 0; - int seconde_actuel = 0; - int old_seconde = 0; - unsigned long int suivant; - int pos_x[2400]; - int pos_y[2400]; - int old_x[2400]; - int old_y[2400]; - int oeufx[5]; - int oeufy[5]; - int murx[30]; - int mury[30]; - char timer[6]; - int *pointeur_segment = &segment; - int *pointeur_go_on = &go_on; - int *pointeur_direction = &direction; - int *pointeur_minute = &minute; - int *pointeur_seconde = &seconde; - unsigned long int *pointeur_suivant = &suivant; - int *pointeur_seconde_actuel = &seconde_actuel; - int *pointeur_old_seconde = &old_seconde; - InitialiserGraphique(); - CreerFenetre(350,100,1200,900); - EffacerEcran(CouleurParComposante(0,0,0)); - suivant = Microsecondes()+CYCLE; - old_seconde=(suivant/1000000)%10; - DessinerScene(murx, mury, minute, seconde ,timer); - InitialiserOeufs(oeufx, oeufy, segment); - Serpent(pos_x, pos_y, old_x, old_y, pointeur_segment, murx, mury, pointeur_go_on, pointeur_direction); - while(go_on){ - Timer( pointeur_minute, pointeur_seconde, pointeur_suivant, pointeur_seconde_actuel, pointeur_old_seconde, timer); - Score(segment); - Controle(pointeur_direction, 0, pointeur_go_on); - Update_Serpent(pos_x, pos_y, segment, old_x, old_y, pointeur_direction); - Collision_Serpent(pos_x, pos_y, segment, murx, mury, pointeur_go_on); - usleep(100000); - Oeuf(pos_x, pos_y, oeufx, oeufy, pointeur_segment); - } - FermerGraphique(); - return EXIT_SUCCESS; -} diff --git a/SAE_semestre1/img/queue.png b/SAE_semestre1/img/queue.png new file mode 100644 index 0000000000000000000000000000000000000000..2190f78834ca0fc673715274e066ee912cff9885 GIT binary patch literal 4714 zcmeHKZEO_B8QwDlTmy~bI*x0Sdb0#d414>1ySMc@2A{zv`M|PItxHoibGx(WjeQ^9 zTl>z0wgf~|$5A3wEK%gB6%ZlC)Kb!X0R0GoDsn?fP?M6VX;T6}k~WD*1r0&Lr0?vV z&$b$=vQ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83LCn#E?+1_aVqV#*&#M?zm=H;4`0&@b-XV?Esu8QfGVw{5i zvN?F=)vr_};C1;+nbvP-DQd}ANbynoMr**h*o{P67Qef+dMQ&`zv#)=!StO-cwJ08 zW!!sl<;zX}`%Z9^bvtTyhp(@AbL}UJbmH{(VLtxa?MFUTc8~A+bkER(Wlg)S>W1<4 z3-(^$|J>=lAD?qh9lxn2d9AH&-=XJD|L)Lh4=&+1)K)K&Utdb)n5yXc3s+f~hKjUo L3XiY9Z^yp@!b~Yg literal 0 HcmV?d00001 diff --git a/SAE_semestre1/snake b/SAE_semestre1/snake new file mode 100755 index 0000000000000000000000000000000000000000..45f2df3eb99dc129b038b350b432bb7df4e350d0 GIT binary patch literal 21216 zcmeHP4Rljgp12yCX_hAqAAm>KL4}JM4&K$I&sdI9m|4vK_L&|NVG*c_e<# zp8Yu6+td8-|MULu|K4}Ml6UWOR#)ZOY)qwm_FYEU`jLWCE*UGXml=R^Hj|CO=S6Hh z`v&j=P80lc0l*dMNM0r!F6sGzq*p?jEbu}>W(q0~36fr}q@5!;3bJB>lU^ZZC2obb z3#6Qcif@!xCiu((r%PuPH0x1pVsnIEtR@o<$ha_Bf2Buc(u+&IxYSdyUj{-!6;E=5 z{%1;iR#*-mrE>nsm{o6$)U(2QQeHtSgVK`sg7sggyjrQ3ka4ua9l|_QP?dKB^e8T0 zHmPP_EX&K)4&|~P6qMm*S2lZB&X|5>bN!TNuP?M_%9@!orp%aL+U75v#$6!4s0!4l z<}X~z^47B$(UiW8*)s4vi9>`Zk{ykI3Onhac>2vvh5DP%q-GVwf84eEw?C-zeoQh{ z53)%zl!!+EDiKfpE83TVtq>ZOMQ}2VWusFWjx6$dIpkl4Y&JWaa?tP3LBAyj{mmTo z3v>8GadhC{n!W{s!%76+06Q0Fp`QRPTfLskLGQ~!ugu}+Pjkpm%OSra2i=~7?#@A9 zn1f!G!=EQ|&==&e!(6V$7QfHc7IX)KE*EnxsH<_+>jAyd+ZNOVbv2dEexF|FUfHY* z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BuP#VN-AFPx=0;K^zk7}vju{7bR33)iEnW{w^}`lEN_hdo7MK|do;k^Fi$R)!oLPU3)K^drmxjDruPDL-i~d%rub@K- zN@&$z20DIy?N|P*eWik`{%T)o_1_JB+EXh1URl0^G|y3@I#QgKzMLMI7c^2)`f4Am zpxU=WgeN(jD3slS9PJU6zSITfzIG zcghMX7?Xmkd~5yj8VlE-E9KNaT0vT0Q6hcXYg_ey1R9Ab`^J1M=Vf)i01=+7?N9px zv%W*>DY!zGFV(H)+22|8)xCBK-eEaluq+qY&n)_CU!mX#Rj`Cs|Nl|ytN5#Ry@Kz5 zf&M>P^wqvk!5v?q|B6L_i`;N2xYck>7*g%0%+kJzUWS*Cjd4GZx=+n2uW$w5hA!=u zmA*PR>X`!~l9Cfx8dvl_FsSb+eYKBO_v7`;_NV?&N$II}JP8_!D1CJ=Q0!WgW^9rG z#;4L(@H24C`s&;%A@yU1rpPEg1?he?v%cDIZ!Z_}%1>oR=@~ebiKhHl`;zC&g@jd} z$}*=BviveL5qYJr#vjF2`etb9B3!h;TxgWZ2b;!W8fTS1YW$@0H08U{5TB0u0$yTa Ys&bX=NMtM`oK<<9kT~C>U_se`0yYJyXaE2J literal 0 HcmV?d00001 diff --git a/SAE_semestre1/Oeuf.c b/SAE_semestre1/src/Oeuf.c similarity index 62% rename from SAE_semestre1/Oeuf.c rename to SAE_semestre1/src/Oeuf.c index 5709d73..f1f2db7 100755 --- a/SAE_semestre1/Oeuf.c +++ b/SAE_semestre1/src/Oeuf.c @@ -1,7 +1,7 @@ #include #include -#include "Oeuf.h" -#include "time.h" +#include "../fichier.h/Oeuf.h" +#include "../fichier.h/time.h" void InitialiserOeufs(int oeufx[], int oeufy[], int segment) { int p; @@ -9,17 +9,17 @@ void InitialiserOeufs(int oeufx[], int oeufy[], int segment) { for (p = 0; p < 5; p++) { oeufx[p] = ((rand() % (55) + 1) * 20); oeufy[p] = ((rand() % (35) + 1) * 20); - ChargerImage("../img/oeuf.png", oeufx[p], oeufy[p],0,0, 20,20); + ChargerImage("img/oeuf.png", oeufx[p], oeufy[p],0,0, 20,20); } } -void Oeuf(int pos_x[], int pos_y[], int oeufx[], int oeufy[], int *segment){ +void Oeuf(int old_x[], int old_y[], int oeufx[], int oeufy[], int *segment){ int p; int oeuf; for (p = 0; p < 5; p++) { - ChargerImage("../img/oeuf.png", oeufx[p], oeufy[p],0,0, 20,20); + ChargerImage("img/oeuf.png", oeufx[p], oeufy[p],0,0, 20,20); } for(p=0; p<5; p++){ - if(oeufx[p]==pos_x[0] && oeufy[p]==pos_y[0]){ + if(oeufx[p]==old_x[0] && oeufy[p]==old_y[0]){ (*segment) +=2; oeufx[p] = ((rand() % (55)+1)*20); oeufy[p] = ((rand() % (35)+1)*20); diff --git a/SAE_semestre1/main.c b/SAE_semestre1/src/main.c similarity index 81% rename from SAE_semestre1/main.c rename to SAE_semestre1/src/main.c index c45fc7b..81fb7ca 100644 --- a/SAE_semestre1/main.c +++ b/SAE_semestre1/src/main.c @@ -1,12 +1,21 @@ #include #include #include -#include "serpent.h" -#include "Oeuf.h" -#include "time.h" -#include "main.h" -#include "menu.h" +#include +#include "../fichier.h/serpent.h" +#include "../fichier.h/Oeuf.h" +#include "../fichier.h/time.h" +#include "../fichier.h/main.h" +#include "../fichier.h/menu.h" + #define CYCLE 100000L +#define DELAI_MILLISECONDES 100 + +void attente(int milliseconds) { + clock_t start_time = clock(); + while ((clock() - start_time) * 1000 / CLOCKS_PER_SEC < milliseconds) { + } +} int lancer_jeu(){ int go_on=1; @@ -37,7 +46,7 @@ int lancer_jeu(){ int *pointeur_pause = &pause; suivant = Microsecondes()+CYCLE; old_seconde=(suivant/1000000)%10; - DessinerScene(murx, mury, minute, seconde ,timer); + Scene(murx, mury, minute, seconde ,timer); InitialiserOeufs(oeufx, oeufy, segment); Serpent(pos_x, pos_y, old_x, old_y, pointeur_segment, murx, mury, &go_on, pointeur_direction); bordure(segment); @@ -49,7 +58,7 @@ int lancer_jeu(){ Update_Serpent(pos_x, pos_y, segment, old_x, old_y, pointeur_direction); dessinerSerpent(pos_x, pos_y, segment, old_x, old_y); Collision_Serpent(pos_x, pos_y, segment, murx, mury, &go_on); - usleep(90000); + attente(DELAI_MILLISECONDES); Oeuf(pos_x, pos_y, oeufx, oeufy, pointeur_segment); } } @@ -63,9 +72,6 @@ int main(void){ if(Menu() == 1){ lancer_jeu(); } - if(Menu() == 0){ - Menu(); - } FermerGraphique(); return EXIT_SUCCESS; } diff --git a/SAE_semestre1/menu.c b/SAE_semestre1/src/menu.c similarity index 71% rename from SAE_semestre1/menu.c rename to SAE_semestre1/src/menu.c index ccfcceb..f96aa39 100755 --- a/SAE_semestre1/menu.c +++ b/SAE_semestre1/src/menu.c @@ -1,12 +1,16 @@ #include #include #include -#include "main.h" -#include "time.h" +#include "../fichier.h/main.h" +#include "../fichier.h/time.h" void Menu_debut(void) { - int af = ChargerSprite("../img/image.jpg"); + int af = ChargerSprite("img/image.jpg"); AfficherSprite(af, 0, 0); } +void Menu_fin(void){ + int fin = ChargerSprite("img/Menu_Fin.jpg"); + AfficherSprite(fin, 0,0); +} int Menu(void) { int choix = 1; InitialiserGraphique(); @@ -22,20 +26,11 @@ int Menu(void) { case XK_q: /* Changement de XK_q à XK_a*/ /*Code pour traiter la touche "a" (fermer le jeu, par exemple)*/ FermerGraphique(); - exit(EXIT_SUCCESS); - return; - /* Ajoutez d'autres cas pour d'autres touches si nécessaire*/ + return choix; } } } } - -int Menu_fin(void){ - int fin = ChargerSprite("../img/Menu_Fin.png"); - AfficherSprite(fin, 0,0); - Menu(); -} - void bordure(int segment){ ChoisirCouleurDessin(CouleurParComposante(0,0,0)); RemplirRectangle(20,720,1180,200); diff --git a/SAE_semestre1/serpent.c b/SAE_semestre1/src/serpent.c similarity index 68% rename from SAE_semestre1/serpent.c rename to SAE_semestre1/src/serpent.c index 5dbe8a5..c207ebc 100755 --- a/SAE_semestre1/serpent.c +++ b/SAE_semestre1/src/serpent.c @@ -1,5 +1,6 @@ #include -#include "serpent.h" +#include "../fichier.h/serpent.h" +#include "../fichier.h/main.h" void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[], int* direction){ int i = 0; @@ -7,37 +8,45 @@ void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_ pos_x[i]=old_x[i-1]; pos_y[i]=old_y[i-1]; } - if (*direction == 1){ + /*Afficher tête serpent selon la direction*/ + if (*direction == 1 && *direction !=2 ){ pos_y[0]=old_y[0]-20; - ChargerImage("../img/tete_up.png", pos_x[0], pos_y[0], 0,0,20,20); + ChargerImage("img/tete_up.png", pos_x[0], pos_y[0], 0,0,20,20); } - if (*direction == 2) { + if (*direction == 2 && *direction !=1) { pos_y[0]=old_y[0]+20; - ChargerImage("../img/tete_down.png", pos_x[0], pos_y[0], 0,0,20,20); + ChargerImage("img/tete_down.png", pos_x[0], pos_y[0], 0,0,20,20); } - if (*direction == 3) { + if (*direction == 3 && *direction !=4) { pos_x[0]=old_x[0]-20; - ChargerImage("../img/tete_left.png", pos_x[0], pos_y[0], 0,0,20,20); + ChargerImage("img/tete_left.png", pos_x[0], pos_y[0], 0,0,20,20); } - if (*direction == 4) { + if (*direction == 4 && *direction !=3) { pos_x[0]=old_x[0]+20; - ChargerImage("../img/tete_right.png", pos_x[0], pos_y[0], 0,0,20,20); + ChargerImage("img/tete_right.png", pos_x[0], pos_y[0], 0,0,20,20); } return; } void dessinerSerpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[]){ int i; + /*Afficher le serpent*/ for (i=0 ; i +#include #include -#include "time.h" -#include "terrain.h" -#include "serpent.h" -#include "main.h" -#include "Oeuf.h" +#include +#include "../fichier.h/time.h" +#include "../fichier.h/terrain.h" +#include "../fichier.h/serpent.h" +#include "../fichier.h/main.h" +#include "../fichier.h/Oeuf.h" -void DessinerScene(int murx[], int mury[], int minute, int seconde, char timer []){ +void Scene(int murx[], int mury[], int minute, int seconde, char timer []){ int mur; int i; snprintf(timer,6,"%02d:%02d", minute ,seconde); @@ -17,6 +19,6 @@ void DessinerScene(int murx[], int mury[], int minute, int seconde, char timer [ for(i=0; i<30; i++){ murx[i] = ((rand() % (55)+1)*20); mury[i] = ((rand() % (35)+1)*20); - ChargerImage("../img/cactus.png", murx[i], mury[i],0,0, 20,20); + ChargerImage("img/cactus.png", murx[i], mury[i],0,0, 20,20); } } diff --git a/SAE_semestre1/time.c b/SAE_semestre1/src/time.c similarity index 90% rename from SAE_semestre1/time.c rename to SAE_semestre1/src/time.c index 9378e0f..f5ef7c8 100755 --- a/SAE_semestre1/time.c +++ b/SAE_semestre1/src/time.c @@ -1,10 +1,11 @@ #include +#include #include #include -#include "time.h" -#include "main.h" -#include "serpent.h" -#define CYCLE 100000L +#include "../fichier.h/time.h" +#include "../fichier.h/main.h" +#include "../fichier.h/serpent.h" +#define CYCLE 1000000L void Score(int segment){ int nombre; diff --git a/SAE_semestre1/terrain.h b/SAE_semestre1/terrain.h deleted file mode 100755 index 038c41d..0000000 --- a/SAE_semestre1/terrain.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TERRAIN_H -#define TERRAIN_H - -void DessinerScene(int murx[30], int mury[30], int minute, int seconde, char timer []); - -#endif