diff --git a/.bashrc b/.bashrc new file mode 100644 index 0000000..e69de29 diff --git a/SAE_semestre1/fichier.h/menu.h b/SAE_semestre1/fichier.h/menu.h new file mode 100755 index 0000000..1ef5cd1 --- /dev/null +++ b/SAE_semestre1/fichier.h/menu.h @@ -0,0 +1,8 @@ +#ifndef MENU_H +#define MENU_H + +void Menu_debut(void); +int Menu(void); +int Menu_fin(void); +void bordure(int segment); +#endif \ No newline at end of file diff --git a/SAE_semestre1/fichier.h/serpent.h b/SAE_semestre1/fichier.h/serpent.h index a63307d..c1b9e68 100755 --- a/SAE_semestre1/fichier.h/serpent.h +++ b/SAE_semestre1/fichier.h/serpent.h @@ -5,4 +5,5 @@ void Serpent(int pos_x[], int pos_y[], int old_x[], int old_y[], int *segment, i void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mury[], int *go_on); void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[], int*); void Controle(int *direction, int last_direction, int *go_on, int *pause); +void dessinerSerpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[]); #endif diff --git a/SAE_semestre1/img/Menu.png b/SAE_semestre1/img/Menu.png deleted file mode 100644 index 6551f28..0000000 Binary files a/SAE_semestre1/img/Menu.png and /dev/null differ diff --git a/SAE_semestre1/img/image.jpg b/SAE_semestre1/img/image.jpg new file mode 100644 index 0000000..0d39c46 Binary files /dev/null and b/SAE_semestre1/img/image.jpg differ diff --git a/SAE_semestre1/img/tete_down.png b/SAE_semestre1/img/tete_down.png deleted file mode 100644 index 91f5e1d..0000000 Binary files a/SAE_semestre1/img/tete_down.png and /dev/null differ diff --git a/SAE_semestre1/img/tete_left.png b/SAE_semestre1/img/tete_left.png deleted file mode 100644 index ead6573..0000000 Binary files a/SAE_semestre1/img/tete_left.png and /dev/null differ diff --git a/SAE_semestre1/img/tete_right.png b/SAE_semestre1/img/tete_right.png deleted file mode 100644 index 90f935e..0000000 Binary files a/SAE_semestre1/img/tete_right.png and /dev/null differ diff --git a/SAE_semestre1/img/tete_up.png b/SAE_semestre1/img/tete_up.png deleted file mode 100644 index e93e56d..0000000 Binary files a/SAE_semestre1/img/tete_up.png and /dev/null differ diff --git a/SAE_semestre1/src/Oeuf.c b/SAE_semestre1/src/Oeuf.c index 00953a7..be5e275 100755 --- a/SAE_semestre1/src/Oeuf.c +++ b/SAE_semestre1/src/Oeuf.c @@ -1,6 +1,7 @@ #include #include #include "../fichier.h/Oeuf.h" +#include "../fichier.h/time.h" void InitialiserOeufs(int oeufx[], int oeufy[], int segment) { int p; @@ -22,6 +23,8 @@ void Oeuf(int pos_x[], int pos_y[], int oeufx[], int oeufy[], int *segment){ (*segment) +=2; oeufx[p] = ((rand() % (55)+1)*20); oeufy[p] = ((rand() % (35)+1)*20); + Score(*segment); } + } } \ No newline at end of file diff --git a/SAE_semestre1/src/main.c b/SAE_semestre1/src/main.c new file mode 100644 index 0000000..62fadb1 --- /dev/null +++ b/SAE_semestre1/src/main.c @@ -0,0 +1,70 @@ +#include +#include +#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 + +int lancer_jeu(){ + int go_on=1; + int pause = 1; + int segment = 10; + 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_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; + int *pointeur_pause = &pause; + 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, &go_on, pointeur_direction); + bordure(segment); + Update_Serpent(pos_x, pos_y, segment, old_x, old_y, pointeur_direction); + while(go_on==1){ + Controle(pointeur_direction, 0, &go_on, pointeur_pause); + if(pause == 1){ + Timer( pointeur_minute, pointeur_seconde, pointeur_suivant, pointeur_seconde_actuel, pointeur_old_seconde, timer); + 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); + Oeuf(pos_x, pos_y, oeufx, oeufy, pointeur_segment); + } + } +} +int main(void){ + int choix = 0; + InitialiserGraphique(); + CreerFenetre(350,100,1200,900); + EffacerEcran(CouleurParComposante(0,0,0)); + Menu(); + if(Menu() == 1){ + lancer_jeu(); + } + FermerGraphique(); + return EXIT_SUCCESS; +} + diff --git a/SAE_semestre1/src/menu.c b/SAE_semestre1/src/menu.c new file mode 100755 index 0000000..0e8e82f --- /dev/null +++ b/SAE_semestre1/src/menu.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include "../fichier.h/main.h" +#include "../fichier.h/time.h" +void Menu_debut(void) { + int af = ChargerSprite("../img/image.jpg"); + AfficherSprite(af, 0, 0); +} +int Menu(void) { + int choix = 1; + InitialiserGraphique(); + Menu_debut(); + + while (1) { + if (ToucheEnAttente()) { + int touche = Touche(); + switch (touche) { + case XK_e: + choix = 1; + return choix; + /* Code pour traiter la touche "e" (fermer le jeu, par exemple)*/ + case XK_a: /* 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*/ + } + } + } +} +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); + RemplirRectangle(0,0,20,900); + RemplirRectangle(0,0,1200,20); + RemplirRectangle(1180,0,1200,900); + Score(segment); +} \ No newline at end of file diff --git a/SAE_semestre1/src/serpent.c b/SAE_semestre1/src/serpent.c index d2f87d5..4b76867 100755 --- a/SAE_semestre1/src/serpent.c +++ b/SAE_semestre1/src/serpent.c @@ -10,28 +10,35 @@ void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_ if (*direction == 1){ pos_y[0]=old_y[0]-20; + ChargerImage("../img/PAUSE.png", pos_x[0], pos_y[0], 0,0,20,20); } if (*direction == 2) { pos_y[0]=old_y[0]+20; + ChargerImage("../img/PAUSE.png", pos_x[0], pos_y[0], 0,0,20,20); } if (*direction == 3) { pos_x[0]=old_x[0]-20; + ChargerImage("../img/PAUSE.png", pos_x[0], pos_y[0], 0,0,20,20); } if (*direction == 4) { pos_x[0]=old_x[0]+20; + ChargerImage("../img/PAUSE.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; for (i=0 ; i=700){ + if (pos_y[0]<20 || pos_y[0] >=720){ *go_on=0; } /*Serpent contre Serpent*/ @@ -55,6 +62,7 @@ void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mu *go_on=0; } } + return; } void Controle(int *direction, int last_direction, int *go_on, int *pause) { diff --git a/SAE_semestre1/src/time.c b/SAE_semestre1/src/time.c index aa6fb39..e8a1521 100755 --- a/SAE_semestre1/src/time.c +++ b/SAE_semestre1/src/time.c @@ -11,8 +11,8 @@ void Score(int segment){ char score[4]; nombre= (segment-10)*25; snprintf(score,4,"%04d0", nombre); - ChoisirCouleurDessin(CouleurParNom("black")); - RemplirRectangle(1100,700,1200,800); + ChoisirCouleurDessin(CouleurParComposante(0,0,0)); + RemplirRectangle(950,725,1300,800); ChoisirCouleurDessin(CouleurParNom("white")); EcrireTexte(1000,760,"Score: ",2); EcrireTexte(1100,760,score,2); @@ -20,7 +20,7 @@ void Score(int segment){ 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); + RemplirRectangle(20,735,200,75); ChoisirCouleurDessin(CouleurParComposante(255,255,255)); EcrireTexte(50,760,"time: ",2); EcrireTexte(120,760,timer,2); diff --git a/bashrc b/bashrc new file mode 100644 index 0000000..e69de29