diff --git a/SAE_semestre1/Makefile b/SAE_semestre1/Makefile index f0f3519..eec7a62 100644 --- a/SAE_semestre1/Makefile +++ b/SAE_semestre1/Makefile @@ -1,25 +1,26 @@ -### VARIABLES ### + CC = gcc -CFLAGS = -lgraph -ansi -SRCDIR = ./src -HDIR = ./fichier.h -ODIR = ./out -OFILES = $(subst src/,out/,$(subst .c,.o,$(shell find $(SRCDIR)/ -type f))) -EXE = game -### BUT PAR DEFAUT ### -but : $(EXE) -### REGLES ESSENTIELLES ### -$(ODIR)/%.o : $(SRCDIR)/%.c - @mkdir -p $(@D) - $(CC) -c $< -o $@ -$(EXE) : $(OFILES) - $(CC) $(CFLAGS) -o $(EXE) $(OFILES) -### REGLES OPTIONNELLES ### -run : $(EXE) - ./$(EXE) -clean : - -rm -rf $(ODIR) -mrproper : - clean but -### BUTS FACTICES ### -.PHONY : but run clean mrproper +CFLAGS = -ansi -pedantic -lgraph +OBJS = main.o serpent.o time.o terrain.o pastille.o + + +serpent: $(OBJS) + $(CC) -o serpent $(OBJS) $(CFLAGS) + +main.o: serpent.h time.h pastille.h main.h + $(CC) -c main.c $(CFLAGS) + +serpent.o: serpent.h + $(CC) -c serpent.c $(CFLAGS) + +timer.o: timer.h serpent.h main.h + $(CC) -c timer.c $(CFLAGS) + +pastille.o: pastille.h serpent.h + $(CC) -c pastille.c $(CFLAGS) + +terrain.o: terrain.h serpent.h time.h main.h pastille.h + $(CC) -c terrain.c $(CFLAGS) + +clean: + rm -f *.0 serpent \ No newline at end of file diff --git a/SAE_semestre1/fichier.h/fonctions.h b/SAE_semestre1/fichier.h/fonctions.h deleted file mode 100644 index 209efff..0000000 --- a/SAE_semestre1/fichier.h/fonctions.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef FONCTIONS_H -#define FONCTIONS_H - - -#endif \ No newline at end of file diff --git a/SAE_semestre1/fichier.h/main.h b/SAE_semestre1/fichier.h/main.h index e1cf47f..39d1c80 100644 --- a/SAE_semestre1/fichier.h/main.h +++ b/SAE_semestre1/fichier.h/main.h @@ -1,6 +1,6 @@ #ifndef MAIN_H #define MAIN_H - void main(void); + int main(void); #endif \ No newline at end of file diff --git a/SAE_semestre1/fichier.h/pastille.h b/SAE_semestre1/fichier.h/pastille.h index c135005..d456071 100644 --- a/SAE_semestre1/fichier.h/pastille.h +++ b/SAE_semestre1/fichier.h/pastille.h @@ -1,6 +1,7 @@ #ifndef PASTILLE_H #define PASTILLE_H -void Pomme(); +void InitialiserPommes(int pommex[], int pommey[], int segment); +void Pomme(int pos_x[], int pos_y[], int pommex[], int pommey[], int *segment); #endif diff --git a/SAE_semestre1/fichier.h/serpent.h b/SAE_semestre1/fichier.h/serpent.h index 1809bcc..738ad6e 100644 --- a/SAE_semestre1/fichier.h/serpent.h +++ b/SAE_semestre1/fichier.h/serpent.h @@ -1,30 +1,8 @@ #ifndef SERPENT_H #define SERPENT_H -#define LARGEUR_FENETRE 1200 -#define HAUTEUR_FENETRE 900 -#define TAILLE_CASE 20 -#define NB_COLONNES 60 -#define NB_LIGNES 40 -#define CYCLE 100000 - - -typedef struct { - int x , y; -} Corps; - -typedef struct { - int longueur; - int directionX; - int directionY; - Corps corps[NB_COLONNES * NB_LIGNES]; -} Serpent; - -void InitialiserSerpent(Serpent *serpent, int x, int y); - -void DeplacerSerpent(Serpent *serpent); - -int VerifierCollision(const Serpent *serpent); - -void DessinerSerpent(const Serpent *serpent); +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); +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[]); +void Controle(int *direction, int last_direction, int *go_on); #endif diff --git a/SAE_semestre1/fichier.h/terrain.h b/SAE_semestre1/fichier.h/terrain.h index 75552ab..0ddf113 100644 --- a/SAE_semestre1/fichier.h/terrain.h +++ b/SAE_semestre1/fichier.h/terrain.h @@ -1,6 +1,6 @@ #ifndef TERRAIN_H #define TERRAIN_H -void DessinerScene(); +void DessinerScene(int murx[30], int mury[30]); #endif diff --git a/SAE_semestre1/fichier.h/time.h b/SAE_semestre1/fichier.h/time.h index 2d5498d..8aa397b 100644 --- a/SAE_semestre1/fichier.h/time.h +++ b/SAE_semestre1/fichier.h/time.h @@ -1,8 +1,7 @@ #ifndef TIME_H #define TIME_H -#define CYCLE 10000L -void Timer(); +void Score(int segment); #endif \ No newline at end of file diff --git a/SAE_semestre1/img/bombe.png b/SAE_semestre1/img/bombe.png deleted file mode 100644 index a42b71b..0000000 Binary files a/SAE_semestre1/img/bombe.png and /dev/null differ diff --git a/SAE_semestre1/img/jeu-snake.jpg b/SAE_semestre1/img/jeu-snake.jpg deleted file mode 100644 index 1526dc2..0000000 Binary files a/SAE_semestre1/img/jeu-snake.jpg and /dev/null differ diff --git a/SAE_semestre1/out/fruit.c b/SAE_semestre1/out/fruit.c deleted file mode 100644 index 3867bc7..0000000 --- a/SAE_semestre1/out/fruit.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include -#include "fruit.h" - -void pomme(){ - int pos_x[60]; - int pos_y[60]; - int p, pp; - int pomme, pommex[5], pommey[5]; - for(p=0; p<6; p++){ - if(pommex[p]==pos_x[0] && pommey[p]==pos_y[0]){ - pommex[p] = ((rand() % (60)+1)*20); - pommey[p] = ((rand() % (27)+1)*20); - } - } - for(pp = 0; pp < 5; ++pp){ - AfficherSprite(pomme, pommex[pp], pommey[pp]); - } -} diff --git a/SAE_semestre1/out/fruit.h b/SAE_semestre1/out/fruit.h deleted file mode 100644 index 8d9f0ab..0000000 --- a/SAE_semestre1/out/fruit.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FRUIT_H -#define FRUIT_H -#include"serpent.h" - -typedef struct { - int x; - int y; - int estMangee; - int sprite; /* Ajout d'un identifiant pour le sprite de la pomme */ -} Pomme; - -void InitialiserPommes(Pomme pommes[], int nombrePommes); -void GenererPommes(Pomme pommes[], int nombrePommes); -void AfficherPommes(Pomme pommes[], int nombrePommes); -void MangerPomme(Pomme pommes[], int nombrePommes, int x, int y); -void DessinerPomme(int x, int y, int sprite); -int ChargerSprite(char *file); -void AfficherSprite(int n, int x, int y); -void LibererSprite(int n); - -#endif diff --git a/SAE_semestre1/out/main.c b/SAE_semestre1/out/main.c deleted file mode 100644 index 7084ae9..0000000 --- a/SAE_semestre1/out/main.c +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include -#include -#include "serpent.h" -#include "fruit.h" - -#define LARGEUR_FENETRE 1600 /* Largeur de la fenêtre (60 colonnes de jeu + murs de 2 cases de chaque côté) */ -#define HAUTEUR_FENETRE 1000 /* Hauteur de la fenêtre (40 lignes de jeu + murs de 2 cases en haut et en bas) */ -#define TAILLE_CASE 20 /* Taille d'une case pour le jeu de Snake */ -#define NB_COLONNES 60 /* Nombre de colonnes du jeu */ -#define NB_LIGNES 40 /* Nombre de lignes du jeu */ -#define CYCLE 100000 -#define VITESSE_SERPENT 100000 -#define NB_POMMES 5 - - -int main() { - - - couleur couleurFond = CouleurParComposante(200, 200, 200); - int touchePressee, i; - Serpent serpent; - unsigned long tempsPrecedent = Microsecondes(); - unsigned long tempsActuel; - couleur couleurMurs = CouleurParComposante(0, 0, 0); - Pomme pommes[NB_POMMES]; - srand(time(NULL)); - - - InitialiserGraphique(); - CreerFenetre(10, 10, LARGEUR_FENETRE, HAUTEUR_FENETRE); - - EffacerEcran(couleurFond); - - AfficherFenetre(); - - pomme(); - - InitialiserSerpent(&serpent, LARGEUR_FENETRE / 2, HAUTEUR_FENETRE / 2); - - while (1) { - if (ToucheEnAttente()) { - int touche = Touche(); - if (touche == XK_Left && serpent.directionX != 1) { - serpent.directionX = -1; - serpent.directionY = 0; - } else if (touche == XK_Right && serpent.directionX != -1) { - serpent.directionX = 1; - serpent.directionY = 0; - } else if (touche == XK_Up && serpent.directionY != 1) { - serpent.directionX = 0; - serpent.directionY = -1; - } else if (touche == XK_Down && serpent.directionY != -1) { - serpent.directionX = 0; - serpent.directionY = 1; - } else if (touche == XK_Escape) { - break; - } - } - - tempsActuel = Microsecondes(); - if (tempsActuel - tempsPrecedent >= VITESSE_SERPENT) { - DeplacerSerpent(&serpent); - if (VerifierCollision(&serpent)) { - FermerGraphique(); - return EXIT_SUCCESS; - } - - EffacerEcran(couleurFond); - DessinerSerpent(&serpent); - AfficherFenetre(); - tempsPrecedent = tempsActuel; - ChoisirCouleurDessin(couleurMurs); - RemplirRectangle(0, HAUTEUR_FENETRE - 80, LARGEUR_FENETRE, 80); - } - } - - for (i = 0; i < NB_POMMES; i++) { - LibererSprite(pommes[i].sprite); - } - - FermerGraphique(); - return EXIT_SUCCESS; -} - - - diff --git a/SAE_semestre1/out/serpent.h b/SAE_semestre1/out/serpent.h deleted file mode 100644 index 512ef37..0000000 --- a/SAE_semestre1/out/serpent.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef SERPENT_H -#define SERPENT_H -#define LARGEUR_FENETRE 1200 -#define HAUTEUR_FENETRE 900 -#define TAILLE_CASE 20 -#define NB_COLONNES 60 -#define NB_LIGNES 40 -#define CYCLE 100000 - - -typedef struct { - int x , y; -} Corps; - -typedef struct { - int longueur; - int directionX; - int directionY; - Corps corps[NB_COLONNES * NB_LIGNES]; -} Serpent; - -void InitialiserSerpent(Serpent *serpent, int x, int y); - -void DeplacerSerpent(Serpent *serpent); - -int VerifierCollision(const Serpent *serpent); - -void DessinerSerpent(const Serpent *serpent); - -#endif \ No newline at end of file diff --git a/SAE_semestre1/out/test.c b/SAE_semestre1/out/test.c deleted file mode 100644 index e31a867..0000000 --- a/SAE_semestre1/out/test.c +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include"serpent.h" - -#include - -#define LARGEUR_FENETRE 1200 -#define HAUTEUR_FENETRE 900 -#define TAILLE_CASE 20 -#define NB_COLONNES 60 -#define NB_LIGNES 40 -#define CYCLE 100000 - - - -void InitialiserSerpent(Serpent *serpent, int x, int y) { - serpent->longueur = 10; - serpent->directionX = 1; - serpent->directionY = 0; - serpent->corps[0].x = x; - serpent->corps[0].y = y; -} - -void DeplacerSerpent(Serpent *serpent) { - int i; - - for ( i = serpent->longueur - 1; i > 0; i--) { - serpent->corps[i] = serpent->corps[i - 1]; - } - - serpent->corps[0].x += serpent->directionX * TAILLE_CASE; - serpent->corps[0].y += serpent->directionY * TAILLE_CASE; -} - - - -int VerifierCollision(const Serpent *serpent) { - int teteX = serpent->corps[0].x; - int teteY = serpent->corps[0].y; - int i; - - if (teteX < 0 || teteX >= LARGEUR_FENETRE || teteY < 0 || teteY >= HAUTEUR_FENETRE-80) { - return 1; - } - - for (i = 1; i < serpent->longueur; i++) { - if (teteX == serpent->corps[i].x && teteY == serpent->corps[i].y) { - return 1; - } - } - - return 0; -} - -void DessinerSerpent(const Serpent *serpent) { - int i; - couleur couleurSerpent = CouleurParComposante(34, 139, 34); - - ChoisirEcran(1); - - EffacerEcran(CouleurParNom("grey")); - - - ChoisirCouleurDessin(couleurSerpent); - /* Afficher la tête du serpent */ - RemplirRectangle(serpent->corps[0].x, serpent->corps[0].y, TAILLE_CASE, TAILLE_CASE); - - - for (i = 0; i < serpent->longueur; i++) { - RemplirRectangle(serpent->corps[i].x, serpent->corps[i].y, TAILLE_CASE, TAILLE_CASE); - } -ChoisirEcran(0); -AfficherFenetre(); -CopierZone(1, 0, 0, 0, LARGEUR_FENETRE, HAUTEUR_FENETRE, 0, 0); - -} diff --git a/SAE_semestre1/src/main.c b/SAE_semestre1/src/main.c index 0425f4f..c1af7a0 100644 --- a/SAE_semestre1/src/main.c +++ b/SAE_semestre1/src/main.c @@ -1,9 +1,10 @@ #include #include #include -#include "serpent.h" -#include "pommes.h" -#include "time.h" +#include "../fichier.h/serpent.h" +#include "../fichier.h/pastille.h" +#include "../fichier.h/time.h" +#include "../fichier.h/main.h" #define CYCLE 10000L @@ -25,17 +26,18 @@ int main(void) { InitialiserGraphique(); CreerFenetre(350,100,1200,900); EffacerEcran(CouleurParComposante(0,0,0)); - suivant = Microsecondes()+CYCLE; - old_seconde=(suivant/1000000)%10; + /* suivant = Microsecondes()+CYCLE; + old_seconde=(suivant/1000000)%10;*/ DessinerScene(murx, mury); InitialiserPommes(pommex, pommey, segment); while(go_on){ - Timer(); + /*Timer();*/ Score(*pointeur_segment); Controle(pointeur_direction, 0, pointeur_go_on); Serpent(pos_x, pos_y, old_x, old_y, pointeur_segment, murx, mury, pointeur_go_on, pointeur_direction); Pomme(pos_x, pos_y, pommex, pommey, pointeur_segment); } + usleep(100000); FermerGraphique(); return EXIT_SUCCESS; } \ No newline at end of file diff --git a/SAE_semestre1/src/pastille.c b/SAE_semestre1/src/pastille.c index 9c5db79..a5499af 100644 --- a/SAE_semestre1/src/pastille.c +++ b/SAE_semestre1/src/pastille.c @@ -1,6 +1,6 @@ #include #include -#include "pommes.h" +#include "../fichier.h/pastille.h" void InitialiserPommes(int pommex[], int pommey[], int segment) { int p; diff --git a/SAE_semestre1/src/serpent.c b/SAE_semestre1/src/serpent.c index fbe6f2c..190aa38 100644 --- a/SAE_semestre1/src/serpent.c +++ b/SAE_semestre1/src/serpent.c @@ -1,5 +1,5 @@ #include -#include "serpent.h" +#include "../fichier.h/serpent.h" void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[]){ int i = 0; diff --git a/SAE_semestre1/src/terrain.c b/SAE_semestre1/src/terrain.c index a19702a..74b66d7 100644 --- a/SAE_semestre1/src/terrain.c +++ b/SAE_semestre1/src/terrain.c @@ -10,7 +10,7 @@ void DessinerScene(int murx[30], int mury[30]){ int mur; int i; int fond; - snprintf(timer,6,"%02d:%02d", minute ,seconde); + /* snprintf(timer,6,"%02d:%02d", minute ,seconde);*/ ChoisirCouleurDessin(CouleurParComposante(91,222,122)); RemplirRectangle(20,20,1160,700); ChoisirCouleurDessin(CouleurParComposante(255,255,255)); diff --git a/SAE_semestre1/src/time.c b/SAE_semestre1/src/time.c index 5e9604c..b4408d0 100644 --- a/SAE_semestre1/src/time.c +++ b/SAE_semestre1/src/time.c @@ -2,26 +2,37 @@ #include #include #include "../fichier.h/time.h" +#include "../fichier.h/main.h" +#include "../fichier.h/serpent.h" #define CYCLE 10000L -/*time*/ - void Update_Timer(void){ - int seconde =0; - int minute=1; - char timer[6]; +int seconde=0; +int minute=0; +int seconde_actuel=0; +int old_seconde=0; +unsigned long int suivant; +char timer[6]; + +void Score(int segment){ + int nombre; + char score[4]; + nombre= (segment-10)*10; + 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(){ 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,"Temps: ",2); - EcrireTexte(160,760,timer,2); + EcrireTexte(50,760,"time: ",2); + EcrireTexte(120,760,timer,2); } -void Timer(void){ -int seconde = 0; -int minute = 0; -int seconde_actuel; -int old_seconde; -unsigned long int suivant; +void Timer(){ if(Microsecondes()> suivant){ suivant = Microsecondes()+CYCLE; seconde_actuel = (suivant/1000000)%10;