This commit is contained in:
Jude Christ AISSI 2023-12-21 15:10:44 +01:00
commit 150aeaeefd
15 changed files with 144 additions and 8 deletions

0
.bashrc Normal file
View File

8
SAE_semestre1/fichier.h/menu.h Executable file
View File

@ -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

View File

@ -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 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 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 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 #endif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 997 KiB

BIN
SAE_semestre1/img/image.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 331 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -1,6 +1,7 @@
#include <graph.h> #include <graph.h>
#include <stdlib.h> #include <stdlib.h>
#include "../fichier.h/Oeuf.h" #include "../fichier.h/Oeuf.h"
#include "../fichier.h/time.h"
void InitialiserOeufs(int oeufx[], int oeufy[], int segment) { void InitialiserOeufs(int oeufx[], int oeufy[], int segment) {
int p; int p;
@ -22,6 +23,8 @@ void Oeuf(int pos_x[], int pos_y[], int oeufx[], int oeufy[], int *segment){
(*segment) +=2; (*segment) +=2;
oeufx[p] = ((rand() % (55)+1)*20); oeufx[p] = ((rand() % (55)+1)*20);
oeufy[p] = ((rand() % (35)+1)*20); oeufy[p] = ((rand() % (35)+1)*20);
} Score(*segment);
}
} }
} }

70
SAE_semestre1/src/main.c Normal file
View File

@ -0,0 +1,70 @@
#include <stdlib.h>
#include <stdio.h>
#include <graph.h>
#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;
}

46
SAE_semestre1/src/menu.c Executable file
View File

@ -0,0 +1,46 @@
#include <stdlib.h>
#include <graph.h>
#include <stdio.h>
#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);
}

View File

@ -10,28 +10,35 @@ void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_
if (*direction == 1){ if (*direction == 1){
pos_y[0]=old_y[0]-20; pos_y[0]=old_y[0]-20;
ChargerImage("../img/PAUSE.png", pos_x[0], pos_y[0], 0,0,20,20);
} }
if (*direction == 2) { if (*direction == 2) {
pos_y[0]=old_y[0]+20; pos_y[0]=old_y[0]+20;
ChargerImage("../img/PAUSE.png", pos_x[0], pos_y[0], 0,0,20,20);
} }
if (*direction == 3) { if (*direction == 3) {
pos_x[0]=old_x[0]-20; pos_x[0]=old_x[0]-20;
ChargerImage("../img/PAUSE.png", pos_x[0], pos_y[0], 0,0,20,20);
} }
if (*direction == 4) { if (*direction == 4) {
pos_x[0]=old_x[0]+20; 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<segment ; i++){ for (i=0 ; i<segment ; i++){
ChargerImage("../img/serpent2.png", pos_x[i], pos_y[i],0,0, 20,20); ChargerImage("../img/serpent2.png", old_x[i], old_y[i],0,0, 20,20);
} }
for (i=0 ; i<segment ; i++){ for (i=0 ; i<segment ; i++){
ChoisirCouleurDessin(CouleurParComposante(218,209,77)); ChoisirCouleurDessin(CouleurParComposante(218,209,77));
RemplirRectangle(pos_x[segment-1], pos_y[segment-1], 20,20); RemplirRectangle(old_x[segment-1], old_y[segment-1], 20,20);
old_x[i]=pos_x[i]; old_x[i]=pos_x[i];
old_y[i]=pos_y[i]; old_y[i]=pos_y[i];
} }
} }
void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mury[], int *go_on){ void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mury[], int *go_on){
int i; int i;
@ -40,7 +47,7 @@ void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mu
*go_on=0; *go_on=0;
} }
/*Serpent contre coté*/ /*Serpent contre coté*/
if (pos_y[0]<20 || pos_y[0] >=700){ if (pos_y[0]<20 || pos_y[0] >=720){
*go_on=0; *go_on=0;
} }
/*Serpent contre Serpent*/ /*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; *go_on=0;
} }
} }
return;
} }
void Controle(int *direction, int last_direction, int *go_on, int *pause) { void Controle(int *direction, int last_direction, int *go_on, int *pause) {

View File

@ -11,8 +11,8 @@ void Score(int segment){
char score[4]; char score[4];
nombre= (segment-10)*25; nombre= (segment-10)*25;
snprintf(score,4,"%04d0", nombre); snprintf(score,4,"%04d0", nombre);
ChoisirCouleurDessin(CouleurParNom("black")); ChoisirCouleurDessin(CouleurParComposante(0,0,0));
RemplirRectangle(1100,700,1200,800); RemplirRectangle(950,725,1300,800);
ChoisirCouleurDessin(CouleurParNom("white")); ChoisirCouleurDessin(CouleurParNom("white"));
EcrireTexte(1000,760,"Score: ",2); EcrireTexte(1000,760,"Score: ",2);
EcrireTexte(1100,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[]){ void Update_Timer(int minute, int seconde, char timer[]){
snprintf(timer,6,"%02d:%02d", minute, seconde); snprintf(timer,6,"%02d:%02d", minute, seconde);
ChoisirCouleurDessin(CouleurParComposante(0,0,0)); ChoisirCouleurDessin(CouleurParComposante(0,0,0));
RemplirRectangle(10,700,12000,800); RemplirRectangle(20,735,200,75);
ChoisirCouleurDessin(CouleurParComposante(255,255,255)); ChoisirCouleurDessin(CouleurParComposante(255,255,255));
EcrireTexte(50,760,"time: ",2); EcrireTexte(50,760,"time: ",2);
EcrireTexte(120,760,timer,2); EcrireTexte(120,760,timer,2);

0
bashrc Normal file
View File