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) {
|
void InitialiserOeufs(int oeufx[], int oeufy[], int segment) {
|
||||||
int p;
|
int p;
|
||||||
int oeuf;
|
int oeuf;
|
||||||
/*Boucles qui initialse 5 pommes aléatoirement*/
|
/*Boucles qui initialse 5 oeufs aléatoirement*/
|
||||||
for (p = 0; p < 5; p++) {
|
for (p = 0; p < 5; p++) {
|
||||||
oeufx[p] = ((rand() % (55) + 1) * 20);
|
oeufx[p] = ((rand() % (55) + 1) * 20);
|
||||||
oeufy[p] = ((rand() % (35) + 1) * 20);
|
oeufy[p] = ((rand() % (35) + 1) * 20);
|
||||||
|
@ -52,43 +52,43 @@ int lancer_jeu(){
|
|||||||
int *pointeur_old_seconde = &old_seconde;
|
int *pointeur_old_seconde = &old_seconde;
|
||||||
int *pointeur_pause = &pause;
|
int *pointeur_pause = &pause;
|
||||||
unsigned long int *pointeur_suivant = &suivant;
|
unsigned long int *pointeur_suivant = &suivant;
|
||||||
suivant = Microsecondes()+CYCLE;
|
suivant = Microsecondes()+CYCLE;
|
||||||
old_seconde=(suivant/1000000)%10;
|
old_seconde=(suivant/1000000)%10;
|
||||||
Scene(murx, mury, minute, seconde ,timer);
|
Scene(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, &go_on, pointeur_direction);
|
Serpent(pos_x, pos_y, old_x, old_y, pointeur_segment, murx, mury, &go_on, pointeur_direction);
|
||||||
bordure(segment);
|
bordure(segment);
|
||||||
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);
|
||||||
|
/*Lancement du jeu*/
|
||||||
while(go_on==1){
|
while(go_on==1){
|
||||||
Controle(pointeur_direction, 0, &go_on, pointeur_pause);
|
Controle(pointeur_direction, 0, &go_on, pointeur_pause);
|
||||||
if(pause == 1){
|
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);
|
||||||
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);
|
||||||
dessinerSerpent(pos_x, pos_y, segment, old_x, old_y);
|
dessinerSerpent(pos_x, pos_y, segment, old_x, old_y);
|
||||||
Collision_Serpent(pos_x, pos_y, segment, murx, mury, &go_on);
|
Collision_Serpent(pos_x, pos_y, segment, murx, mury, &go_on);
|
||||||
attente(DELAI_MILLISECONDES);
|
attente(DELAI_MILLISECONDES);
|
||||||
Oeuf(pos_x, pos_y, oeufx, oeufy, pointeur_segment);
|
Oeuf(pos_x, pos_y, oeufx, oeufy, pointeur_segment);
|
||||||
}else{
|
}else{
|
||||||
Controle(pointeur_direction, 0, &go_on, pointeur_pause);
|
Controle(pointeur_direction, 0, &go_on, pointeur_pause);
|
||||||
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);
|
||||||
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);
|
||||||
dessinerSerpent(pos_x, pos_y, segment, old_x, old_y);
|
dessinerSerpent(pos_x, pos_y, segment, old_x, old_y);
|
||||||
Collision_Serpent(pos_x, pos_y, segment, murx, mury, &go_on);
|
Collision_Serpent(pos_x, pos_y, segment, murx, mury, &go_on);
|
||||||
attente(DELAI_MILLISECONDES);
|
attente(DELAI_MILLISECONDES);
|
||||||
Oeuf(pos_x, pos_y, oeufx, oeufy, pointeur_segment);
|
Oeuf(pos_x, pos_y, oeufx, oeufy, pointeur_segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int main(void){
|
int main(void){
|
||||||
int choix = 0;
|
int choix = 0;
|
||||||
InitialiserGraphique();
|
InitialiserGraphique();
|
||||||
CreerFenetre(350,100,1200,900);
|
CreerFenetre(350,100,1200,900);
|
||||||
EffacerEcran(CouleurParComposante(0,0,0));
|
EffacerEcran(CouleurParComposante(0,0,0));
|
||||||
Menu();
|
Menu();
|
||||||
if(Menu() == 1){
|
if(Menu() == 1){
|
||||||
lancer_jeu();
|
lancer_jeu();
|
||||||
}
|
}
|
||||||
FermerGraphique();
|
FermerGraphique();
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <graph.h>
|
#include <graph.h>
|
||||||
|
|
||||||
#include "../fichier.h/main.h"
|
#include "../fichier.h/main.h"
|
||||||
@ -19,7 +18,6 @@ int Menu(void) {
|
|||||||
int choix = 1;
|
int choix = 1;
|
||||||
InitialiserGraphique();
|
InitialiserGraphique();
|
||||||
Menu_debut();
|
Menu_debut();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (ToucheEnAttente()) {
|
if (ToucheEnAttente()) {
|
||||||
int touche = Touche();
|
int touche = Touche();
|
||||||
@ -27,8 +25,7 @@ int Menu(void) {
|
|||||||
case XK_e:
|
case XK_e:
|
||||||
choix = 1;
|
choix = 1;
|
||||||
return choix;
|
return choix;
|
||||||
case XK_q: /* Changement de XK_q à XK_a*/
|
case XK_q:
|
||||||
/*Code pour traiter la touche "a" (fermer le jeu, par exemple)*/
|
|
||||||
FermerGraphique();
|
FermerGraphique();
|
||||||
return choix;
|
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) {
|
void Controle(int *direction, int last_direction, int *go_on, int *pause) {
|
||||||
int t;
|
int t;
|
||||||
int Pause = ChargerSprite("img/PAUSE.png");
|
|
||||||
while(ToucheEnAttente()) {
|
while(ToucheEnAttente()) {
|
||||||
t = Touche();
|
t = Touche();
|
||||||
switch(t) {
|
switch(t) {
|
||||||
@ -109,7 +108,7 @@ void Controle(int *direction, int last_direction, int *go_on, int *pause) {
|
|||||||
return;
|
return;
|
||||||
case XK_space :
|
case XK_space :
|
||||||
*pause = 1;
|
*pause = 1;
|
||||||
AfficherSprite(Pause, 400, 720);
|
ChargerImage("img/PAUSE.png", 400,720,0,0,400,150);
|
||||||
while(*pause){
|
while(*pause){
|
||||||
t = Touche();
|
t = Touche();
|
||||||
if (t == XK_space){
|
if (t == XK_space){
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <graph.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <graph.h>
|
#include <graph.h>
|
||||||
|
|
||||||
@ -14,13 +12,13 @@
|
|||||||
void Scene(int murx[], int mury[], int minute, int seconde, char timer []){
|
void Scene(int murx[], int mury[], int minute, int seconde, char timer []){
|
||||||
int mur;
|
int mur;
|
||||||
int i;
|
int i;
|
||||||
snprintf(timer,6,"%02d:%02d", minute ,seconde);
|
snprintf(timer,6,"%02d:%02d", minute ,seconde);
|
||||||
ChoisirCouleurDessin(CouleurParComposante(218,209,77));
|
ChoisirCouleurDessin(CouleurParComposante(218,209,77));
|
||||||
RemplirRectangle(20,20,1160,700);
|
RemplirRectangle(20,20,1160,700);
|
||||||
ChoisirCouleurDessin(CouleurParComposante(255,255,255));
|
ChoisirCouleurDessin(CouleurParComposante(255,255,255));
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
/*Initialisation de 30 obstacles */
|
/*Initialisation de 30 obstacles */
|
||||||
for(i=0; i<30; i++){
|
for(i=0; i<30; i++){
|
||||||
murx[i] = ((rand() % (55)+1)*20);
|
murx[i] = ((rand() % (55)+1)*20);
|
||||||
mury[i] = ((rand() % (35)+1)*20);
|
mury[i] = ((rand() % (35)+1)*20);
|
||||||
ChargerImage("img/cactus.png", murx[i], mury[i],0,0, 20,20);
|
ChargerImage("img/cactus.png", murx[i], mury[i],0,0, 20,20);
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <graph.h>
|
#include <graph.h>
|
||||||
|
|
||||||
#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 1000000L
|
#define CYCLE 1000000L
|
||||||
|
|
||||||
|
/*Affichage du score*/
|
||||||
void Score(int segment){
|
void Score(int segment){
|
||||||
int nombre;
|
int nombre;
|
||||||
char score[4];
|
char score[4];
|
||||||
|
Loading…
Reference in New Issue
Block a user