ajout commentaire + organisation du code + réglage menu pause
This commit is contained in:
parent
b9e58985ea
commit
95411d5a1f
Binary file not shown.
@ -8,7 +8,7 @@
|
||||
void InitialiserOeufs(int oeufx[], int oeufy[], int segment) {
|
||||
int p;
|
||||
int oeuf;
|
||||
/*Boucles qui initialse 5 pommes aléatoirement*/
|
||||
/*Boucles qui initialse 5 oeufs aléatoirement*/
|
||||
for (p = 0; p < 5; p++) {
|
||||
oeufx[p] = ((rand() % (55) + 1) * 20);
|
||||
oeufy[p] = ((rand() % (35) + 1) * 20);
|
||||
|
@ -52,43 +52,43 @@ int lancer_jeu(){
|
||||
int *pointeur_old_seconde = &old_seconde;
|
||||
int *pointeur_pause = &pause;
|
||||
unsigned long int *pointeur_suivant = &suivant;
|
||||
suivant = Microsecondes()+CYCLE;
|
||||
old_seconde=(suivant/1000000)%10;
|
||||
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);
|
||||
Update_Serpent(pos_x, pos_y, segment, old_x, old_y, pointeur_direction);
|
||||
suivant = Microsecondes()+CYCLE;
|
||||
old_seconde=(suivant/1000000)%10;
|
||||
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);
|
||||
Update_Serpent(pos_x, pos_y, segment, old_x, old_y, pointeur_direction);
|
||||
/*Lancement du jeu*/
|
||||
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);
|
||||
attente(DELAI_MILLISECONDES);
|
||||
Oeuf(pos_x, pos_y, oeufx, oeufy, pointeur_segment);
|
||||
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);
|
||||
attente(DELAI_MILLISECONDES);
|
||||
Oeuf(pos_x, pos_y, oeufx, oeufy, pointeur_segment);
|
||||
}else{
|
||||
Controle(pointeur_direction, 0, &go_on, pointeur_pause);
|
||||
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);
|
||||
attente(DELAI_MILLISECONDES);
|
||||
Oeuf(pos_x, pos_y, oeufx, oeufy, pointeur_segment);
|
||||
Controle(pointeur_direction, 0, &go_on, pointeur_pause);
|
||||
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);
|
||||
attente(DELAI_MILLISECONDES);
|
||||
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();
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(350,100,1200,900);
|
||||
EffacerEcran(CouleurParComposante(0,0,0));
|
||||
Menu();
|
||||
if(Menu() == 1){
|
||||
lancer_jeu();
|
||||
}
|
||||
FermerGraphique();
|
||||
return EXIT_SUCCESS;
|
||||
FermerGraphique();
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <graph.h>
|
||||
|
||||
#include "../fichier.h/main.h"
|
||||
@ -19,7 +18,6 @@ int Menu(void) {
|
||||
int choix = 1;
|
||||
InitialiserGraphique();
|
||||
Menu_debut();
|
||||
|
||||
while (1) {
|
||||
if (ToucheEnAttente()) {
|
||||
int touche = Touche();
|
||||
@ -27,8 +25,7 @@ int Menu(void) {
|
||||
case XK_e:
|
||||
choix = 1;
|
||||
return choix;
|
||||
case XK_q: /* Changement de XK_q à XK_a*/
|
||||
/*Code pour traiter la touche "a" (fermer le jeu, par exemple)*/
|
||||
case XK_q:
|
||||
FermerGraphique();
|
||||
return choix;
|
||||
}
|
||||
|
@ -79,7 +79,6 @@ 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, int *pause) {
|
||||
int t;
|
||||
int Pause = ChargerSprite("img/PAUSE.png");
|
||||
while(ToucheEnAttente()) {
|
||||
t = Touche();
|
||||
switch(t) {
|
||||
@ -109,7 +108,7 @@ void Controle(int *direction, int last_direction, int *go_on, int *pause) {
|
||||
return;
|
||||
case XK_space :
|
||||
*pause = 1;
|
||||
AfficherSprite(Pause, 400, 720);
|
||||
ChargerImage("img/PAUSE.png", 400,720,0,0,400,150);
|
||||
while(*pause){
|
||||
t = Touche();
|
||||
if (t == XK_space){
|
||||
|
@ -1,7 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <graph.h>
|
||||
#include <time.h>
|
||||
#include <graph.h>
|
||||
|
||||
@ -14,13 +12,13 @@
|
||||
void Scene(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));
|
||||
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));
|
||||
/*Initialisation de 30 obstacles */
|
||||
for(i=0; i<30; i++){
|
||||
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);
|
||||
|
@ -1,12 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <graph.h>
|
||||
|
||||
#include "../fichier.h/time.h"
|
||||
#include "../fichier.h/main.h"
|
||||
#include "../fichier.h/serpent.h"
|
||||
#define CYCLE 1000000L
|
||||
|
||||
/*Affichage du score*/
|
||||
void Score(int segment){
|
||||
int nombre;
|
||||
char score[4];
|
||||
|
Loading…
Reference in New Issue
Block a user