2023-12-14 15:00:02 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2023-12-19 14:52:23 +01:00
|
|
|
#include <graph.h>
|
2023-12-22 15:11:29 +01:00
|
|
|
#include <time.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"
|
2023-12-21 12:29:12 +01:00
|
|
|
#define CYCLE 100000L
|
2023-12-22 15:11:29 +01:00
|
|
|
#define DELAI_MILLISECONDES 100
|
|
|
|
void attente(int milliseconds) {
|
|
|
|
clock_t start_time = clock();
|
|
|
|
while ((clock() - start_time) * 1000 / CLOCKS_PER_SEC < milliseconds) {
|
|
|
|
}
|
|
|
|
}
|
2023-12-21 12:29:12 +01:00
|
|
|
int lancer_jeu(){
|
2023-12-21 14:32:41 +01:00
|
|
|
int go_on=1;
|
2023-12-21 12:29:12 +01:00
|
|
|
int pause = 1;
|
2023-12-19 14:52:23 +01:00
|
|
|
int segment = 10;
|
|
|
|
int direction = 4;
|
2023-12-20 21:26:34 +01:00
|
|
|
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];
|
2023-12-19 14:52:23 +01:00
|
|
|
int murx[30];
|
|
|
|
int mury[30];
|
2023-12-20 21:26:34 +01:00
|
|
|
char timer[6];
|
2023-12-19 14:52:23 +01:00
|
|
|
int *pointeur_segment = &segment;
|
|
|
|
int *pointeur_direction = &direction;
|
2023-12-20 21:26:34 +01:00
|
|
|
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;
|
2023-12-21 12:29:12 +01:00
|
|
|
int *pointeur_pause = &pause;
|
2023-12-20 21:26:34 +01:00
|
|
|
suivant = Microsecondes()+CYCLE;
|
|
|
|
old_seconde=(suivant/1000000)%10;
|
2023-12-22 15:11:29 +01:00
|
|
|
Scene(murx, mury, minute, seconde ,timer);
|
2023-12-20 21:26:34 +01:00
|
|
|
InitialiserOeufs(oeufx, oeufy, segment);
|
2023-12-21 14:32:41 +01:00
|
|
|
Serpent(pos_x, pos_y, old_x, old_y, pointeur_segment, murx, mury, &go_on, pointeur_direction);
|
|
|
|
bordure(segment);
|
2023-12-21 14:55:45 +01:00
|
|
|
Update_Serpent(pos_x, pos_y, segment, old_x, old_y, pointeur_direction);
|
2023-12-21 14:32:41 +01:00
|
|
|
while(go_on==1){
|
|
|
|
Controle(pointeur_direction, 0, &go_on, pointeur_pause);
|
2023-12-21 12:29:12 +01:00
|
|
|
if(pause == 1){
|
2023-12-20 21:26:34 +01:00
|
|
|
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);
|
2023-12-21 14:55:45 +01:00
|
|
|
dessinerSerpent(pos_x, pos_y, segment, old_x, old_y);
|
2023-12-21 14:32:41 +01:00
|
|
|
Collision_Serpent(pos_x, pos_y, segment, murx, mury, &go_on);
|
2023-12-22 15:11:29 +01:00
|
|
|
attente(DELAI_MILLISECONDES);
|
2023-12-20 21:26:34 +01:00
|
|
|
Oeuf(pos_x, pos_y, oeufx, oeufy, pointeur_segment);
|
2023-12-14 15:00:02 +01:00
|
|
|
}
|
2023-12-21 12:29:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
int main(void){
|
|
|
|
int choix = 0;
|
|
|
|
InitialiserGraphique();
|
|
|
|
CreerFenetre(350,100,1200,900);
|
|
|
|
EffacerEcran(CouleurParComposante(0,0,0));
|
2023-12-21 14:32:41 +01:00
|
|
|
Menu();
|
|
|
|
if(Menu() == 1){
|
2023-12-21 12:29:12 +01:00
|
|
|
lancer_jeu();
|
|
|
|
}
|
2023-12-14 15:00:02 +01:00
|
|
|
FermerGraphique();
|
2023-12-19 14:52:23 +01:00
|
|
|
return EXIT_SUCCESS;
|
2023-12-20 21:26:34 +01:00
|
|
|
}
|