ajout menu mais non fonctionnel

This commit is contained in:
Jude Christ AISSI 2023-12-21 12:29:12 +01:00
parent 8f26f7027d
commit 6b14cf17e8
11 changed files with 55 additions and 32 deletions

View File

@ -1,6 +1,7 @@
#ifndef MAIN_H #ifndef MAIN_H
#define MAIN_H #define MAIN_H
int main(void); int jeu(void);
int main(void);
#endif #endif

View File

@ -1,6 +1,10 @@
#ifndef MENU_H #ifndef MENU_H
#define MENU_H #define MENU_H
void menu(void); typedef struct {
int x, y, L, H;
} zone;
int check_zone(zone z, int x, int y);
void afficher_menu(zone jouer, zone quitter, int *jeu);
#endif #endif

View File

@ -4,5 +4,5 @@
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 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 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); void Controle(int *direction, int last_direction, int *go_on, int *pause);
#endif #endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -5,10 +5,12 @@
#include "../fichier.h/Oeuf.h" #include "../fichier.h/Oeuf.h"
#include "../fichier.h/time.h" #include "../fichier.h/time.h"
#include "../fichier.h/main.h" #include "../fichier.h/main.h"
#include "../fichier.h/menu.h"
#define CYCLE 10000L #define CYCLE 100000L
int main(void){ int lancer_jeu(){
int pause = 1;
int segment = 10; int segment = 10;
int go_on = 1; int go_on = 1;
int direction = 4; int direction = 4;
@ -34,23 +36,35 @@ int main(void){
unsigned long int *pointeur_suivant = &suivant; unsigned long int *pointeur_suivant = &suivant;
int *pointeur_seconde_actuel = &seconde_actuel; int *pointeur_seconde_actuel = &seconde_actuel;
int *pointeur_old_seconde = &old_seconde; int *pointeur_old_seconde = &old_seconde;
InitialiserGraphique(); int *pointeur_pause = &pause;
CreerFenetre(350,100,1200,900);
EffacerEcran(CouleurParComposante(0,0,0));
suivant = Microsecondes()+CYCLE; suivant = Microsecondes()+CYCLE;
old_seconde=(suivant/1000000)%10; old_seconde=(suivant/1000000)%10;
DessinerScene(murx, mury, minute, seconde ,timer); DessinerScene(murx, mury, minute, seconde ,timer);
InitialiserOeufs(oeufx, oeufy, segment); InitialiserOeufs(oeufx, oeufy, segment);
Serpent(pos_x, pos_y, old_x, old_y, pointeur_segment, murx, mury, pointeur_go_on, pointeur_direction); Serpent(pos_x, pos_y, old_x, old_y, pointeur_segment, murx, mury, pointeur_go_on, pointeur_direction);
while(go_on){ while(go_on){
Controle(pointeur_direction, 0, pointeur_go_on, pointeur_pause);
if(pause == 1){
Timer( pointeur_minute, pointeur_seconde, pointeur_suivant, pointeur_seconde_actuel, pointeur_old_seconde, timer); 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); 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); Collision_Serpent(pos_x, pos_y, segment, murx, mury, pointeur_go_on);
Score(segment);
usleep(100000); usleep(100000);
Oeuf(pos_x, pos_y, oeufx, oeufy, pointeur_segment); 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));
afficher_menu(&choix);
while( choix == 1){
lancer_jeu();
}
FermerGraphique(); FermerGraphique();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -1,25 +1,24 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <graph.h>
#include "../fichier.h/menu.h" #include "../fichier.h/menu.h"
int check_zone(zone z, int x, int y) {
int MenuDebut(){ return x >= z.x && x <= z.x + z.L && y >= z.y && y <= z.y + z.H;
InitialiserGraphique();
EcrireTexte(1000,760,"Score", 2);
} }
int menu(){
while(menu){ void afficher_menu(zone jouer, zone quitter, int *choix) {
while(ToucheEnAttente()){ ChargerImageFond("../img/Menu.png");
t = Touche(); while(1){
switch(t3){ SourisPosition();
case XK_q :
FermerGraphique(); if(SourisCliquee()){
return EXIT_SUCCESS; int x = _X;
return; int y = _Y;
case XK_Right : if (check_zone(jouer, _X, _Y)){
menu = 0; *choix = 1;
return return;
} }
} }
} }
} }

View File

@ -57,7 +57,7 @@ void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mu
} }
} }
void Controle(int *direction, int last_direction, int *go_on) { void Controle(int *direction, int last_direction, int *go_on, int *pause) {
int t; int t;
while(ToucheEnAttente()) { while(ToucheEnAttente()) {
t = Touche(); t = Touche();
@ -86,8 +86,13 @@ void Controle(int *direction, int last_direction, int *go_on) {
*direction = 0; *direction = 0;
*go_on = 0; *go_on = 0;
return; return;
case XK_p: case XK_space:
*direction = 0; if (*pause == 0 ){
*pause == 1;
}else{
*pause = 0;
ChargerImage("../img/PAUSE.png", 400,200,0,0,350,300);
}
} }
} }
} }

View File

@ -4,7 +4,7 @@
#include "../fichier.h/time.h" #include "../fichier.h/time.h"
#include "../fichier.h/main.h" #include "../fichier.h/main.h"
#include "../fichier.h/serpent.h" #include "../fichier.h/serpent.h"
#define CYCLE 10000L #define CYCLE 100000L
void Score(int segment){ void Score(int segment){
int nombre; int nombre;